首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不更新新条目的PHPlot与mySQL

不更新新条目的PHPlot与mySQL
EN

Stack Overflow用户
提问于 2014-01-15 18:35:47
回答 1查看 876关注 0票数 0

我有个问题,可能很蠢,我刚开始用这个。我有一个包含5个条目的数据库,我用PHPlot绘制了一个图表,当我添加一个新条目时,它不会更新。我将其设置为在一行图中显示最后5个条目,但它只显示了3条(当我编写脚本时只有3条)。任何帮助都是非常感谢的。这是密码。

代码语言:javascript
复制
<?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很讨厌。非常感谢。所有的帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-15 19:08:59

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

代码语言:javascript
复制
$rows = mysql_num_rows($qry); 
for($i = 0; $i < $rows; $i++)
    $data[$i] = mysql_fetch_array($qry);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21145568

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档