带有mySQL的PHP​​lot没有更新新条目

时间:2014-01-15 18:35:47

标签: php mysql graph charts graphing

我有一个问题,它可能是愚蠢的,我刚开始使用它。我有一个包含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搞砸了。非常感谢。所有和任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:0)

你的for循环只能处理3个条目。 你可以使用mysql_num_rows($qry)

$rows = mysql_num_rows($qry); 
for($i = 0; $i < $rows; $i++)
    $data[$i] = mysql_fetch_array($qry);
相关问题