0

我想根据数据库生成折线图。我第一次使用融合图表时,我按照融合图表文档中动态图表的程序进行操作。这是我的php页面代码:

<?php
include("Includes/FusionCharts.php");
include("Includes/DBconn.php");
?>
<html>
    <title> Blood Pressure</title>
    <head>
        <script language="javascript" src="FusionCharts/FusionChart.js"></script>

    </head>
    <body>
    <center>
        <?php

        //connect to the DB
        $link= connectToDB();
        //$strXML will be used to store the entire XML document generated
   //Generate the graph element
   $strXML = "<graph caption='Blood Pressure Reading' subCaption='By Patient'xaxisname='Months' yaxisname='Blood Pressure' hovercapbg='F5589A' hovercapborder='F5589A' rotateNames='1' yAxisMaxValue='200'>";

   //Fetch records from database
   $query= "select * from patient_health";
   $result = mysql_query($query) or die(mysql_error());
   echo $result;

   //Iterate through each patient blood pressure systole

       while($row= mysql_num_rows($result)){
           //Generate the setname and value
          // echo $row['Date'];
           //echo $row['Systole_reading'];
           $strXML.="<set name='".$row['Date']."'value='".  $row['Systole_reading']."'/>";
           mysql_free_result($result);
       }     

       //Finally, close <graph> element
   $strXML .= "</graph>";
   //Create the chart - Pie 3D Chart with data from $strXML
   echo renderChart("FusionCharts/FCF_Line.swf", "", $strXML, "BloodPressure", 650, 450);

       ?>

    </center>

    </body>

</html>

我收到错误消息:警告:mysql_num_rows(): 6 is not a valid MySQL result resource in C:\xampp\htdocs\phpfusion\ramfusion\Chart.php on line 28 Chart。任何人都可以在这方面帮助我,提前谢谢你,Ramsai

4

2 回答 2

1

因为您试图循环遍历行数(6)而不是行本身。尝试

while($row= mysql_fetch_assoc($result)){

而不是在你的循环上。这将返回行的关联数组,然后将循环遍历,将每一行放入$row.

于 2012-04-20T11:28:57.553 回答
1

再检查几件事:

a) SWF 的路径是正确的。
b) 页面中加载了 FusionCharts.js
c) 在 TEXTAREA 中打印 $strXML 以检查是否生成了正确的 XML。

于 2012-04-21T07:37:02.707 回答