我正在使用 ZingChart 。在加载页面时,图表成功地从 MySql 数据库加载数据。但是在数据库更新一段时间后如何加载最新数据?请帮帮我。我已经在我的index.php页面中尝试了以下代码来执行此操作,但它不起作用。
<script>
var myData=[
<?php
$conn =mysql_connect("localhost","root","") or die ("we couldn't connect!");
mysql_select_db("webauth");
$rs = mysql_query("SELECT * FROM test") or die(mysql_error());
while($row = mysql_fetch_array($rs))
{
echo $row['label'].',';
}?>];
var myLabels=[<?php
$conn =mysql_connect("localhost","root","") or die ("we couldn't connect!");
mysql_select_db("webauth");
$rs = mysql_query("SELECT * FROM test") or die(mysql_error());
while($row2 = mysql_fetch_array($rs))
{
echo '"'.$row2['value'].'"'.',';
}?>];
window.onload=function(){
window.alert(myData);
zingchart.render({
id:'chartDiv',
data:{
"type":"bar",
"scale-x":{
"values":myLabels,
},
"series":[
{
"values":myData
}
]
,
"refresh":{
"type":"feed",
"transport":"http",
"url":"feed.php?",
"interval":200
},
}
});
}
</script>
并在feed.php页面中使用此代码
<script>
var myData=[
<?php
?>
[
{
$conn =mysql_connect("localhost","root","") or die ("we couldn't connect!");
mysql_select_db("webauth");
$rs = mysql_query("SELECT * FROM test") or die(mysql_error());
while($row = mysql_fetch_array($rs))
{
"plot<?php echo $row['label'].',';
}?>"];
}
]
var myLabels=[<?php
?>
[
{
$conn =mysql_connect("localhost","root","") or die ("we couldn't connect!");
mysql_select_db("webauth");
$rs = mysql_query("SELECT * FROM test") or die(mysql_error());
while($row2 = mysql_fetch_array($rs))
{
"plot<?php echo '"'.$row2['value'].'"'.',';
}?>"];
}
]
</script>