我有个问题,可能很蠢,我刚开始用这个。我有一个包含5个条目的数据库,我用PHPlot绘制了一个图表,当我添加一个新条目时,它不会更新。我将其设置为在一行图中显示最后5个条目,但它只显示了3条(当我编写脚本时只有3条)。任何帮助都是非常感谢的。这是密码。
<?php
//database connection
$dbname="localhost";
$dbun="username";
$dbpw="password";
$database="medtrack";
//my table1
$table="members";
// Connect to database
$conn = mysql_connect("$dbname", "$dbun", "$dbpw") or die(mysql_error());
mysql_select_db("$database", $conn) or die(mysql_error());
// Include files
include 'phplot/phplot.php';
// start array
$qry = mysql_query("SELECT * FROM 36_mood ORDER BY 'id' DESC");
for($i = 0; $i < 3; $i++)
$data[$i] = mysql_fetch_array($qry);
//array 1, id I didn't change the name yet, sorry
$date1=$data[0]['id'];
$date2=$data[1]['id'];
$date3=$data[2]['id'];
$date4=$data[3]['id'];
$date5=$data[4]['id'];
//array 2, moods - these are on a scale of 0-10, stored as int in the database
$mood1=$data[0]['mood'];
$mood2=$data[1]['mood'];
$mood3=$data[2]['mood'];
$mood4=$data[3]['mood'];
$mood4=$data[4]['mood'];
//Define the object
$plot2 = new PHPlot();
//Define some data
$example_data = array(
array(1,$mood1),
array(2,$mood2),
array(3,$mood3),
array(4,$mood4),
array(5,$mood5),
);
$plot2->SetDataValues($example_data);
//Turn off X axis ticks and labels because they get in the way:
$plot2->SetXTickLabelPos('none');
$plot2->SetXTickPos('none');
//Draw it
$plot2->DrawGraph();
?>所有的帮助都是感激的。我在想,如果这个方法不起作用的话,每次有人点击图表页面时,都会动态生成一个页面。有什么想法吗?我试过libchart,但它不喜欢MySQL,我可能会再试一次。我对Javascript很讨厌。非常感谢。所有的帮助都是非常感谢的。
发布于 2014-01-15 19:08:59
您的for-循环只能处理3个条目.您可以使用mysql_num_rows($qry)
$rows = mysql_num_rows($qry);
for($i = 0; $i < $rows; $i++)
$data[$i] = mysql_fetch_array($qry);https://stackoverflow.com/questions/21145568
复制相似问题