我有一个 SQLite 数据库,正在尝试使用 Highcharts、PHP 和 Javascript 在折线图上绘制数据。我正在为每个用户绘制一个系列(一个用户是每个元组的文本值),但是在通过 PHP 循环检索后续用户时遇到了麻烦。
$dbhandle = sqlite_open('db/test.db', 0666, $error);
if (!$dbhandle) die ($error);
$query5 = "SELECT DISTINCT User FROM Events";
$ok0 = sqlite_query($dbhandle, $query5, $error_msg);
if (!$ok0)
{
die("dead" . $error_msg);
}
$rows = sqlite_num_rows($ok0);
echo
"for(var i=2; i<$rows; i++) // start of JS loop.
//$rows is 4; I am graphing 2 series here
{";
$array = sqlite_fetch_array($ok0, SQLITE_ASSOC); // $ok0 is the unique list
// of users. After graphing one series, I want to grab the next user to graph
echo "chart.addSeries({
name: '{$array["User"]}',
data: [";
for($i=0; $i<$diff+1; $i++)
{
$target = date("D, j M", (strtotime($_GET["start"]) + $i * 24 * 3600));
$query6 = "SELECT * FROM Events WHERE User = '{$array["User"]}' AND Start LIKE '%{$target}%'";
$result6 = sqlite_query($dbhandle, $query6);
if (!$result6) die("Cannot execute query.");
$num = sqlite_num_rows($result6);
if($i==($diff))
{
echo $num;
}
else
echo $num . ", ";
}?>],
pointStart:
<?php
$date = DateTime::createFromFormat('D M d Y', urldecode($_GET["start"]));
echo $date->getTimestamp()*1000;?>,
pointInterval: 24 * 3600 * 1000 // one day
});
<?php echo "}";?> // end of JS loop
结果确实绘制了另外两个系列,但它们都是来自同一用户的相同数据。它看起来不像带有 sqlite_fetch_array() 的循环正确返回下一个用户。任何人都可以在这里看到问题吗?也许与我将 Javascript 与 PHP 集成的方式有关?