0

I want to generate line graph based on database. First time i am using fusion charts, i follow the procedure for the dynamic charts in fusion charts documentation. Here is my php page code:

<?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>

I am getting error as: Warning: mysql_num_rows(): 6 is not a valid MySQL result resource in C:\xampp\htdocs\phpfusion\ramfusion\Chart.php on line 28 Chart. Can anyone please help me in this regard, Thank you in advance, Ramsai

ramsai
  • 121
  • 1
  • 7
  • 22

2 Answers2

1

Because your trying to loop over the number of rows (6) rather than the rows themselves. Try

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

instead on your loop. This will return an associative array of the rows, which will then get looped over, placing each row into $row.

Paystey
  • 3,287
  • 2
  • 18
  • 32
  • @paystay,thank you very much for your response i change to while($row= mysql_fetch_assoc($result)){ but it still it is throwing the same error. – ramsai Apr 20 '12 at 11:35
  • The code you posted is Chart.php right? and Line 28 was the one with mysql_num_rows on, which I suggested changing to the above. If all that's correct you shouldn't be getting that error still, update your code in your question and we'll take a look – Paystey Apr 20 '12 at 12:08
  • now i am not getting any error but php page is not reading the data in xml tags i think, i once again giving my modified chart.php page: – ramsai Apr 20 '12 at 12:38
  • @paystay now i am not getting any errors but the charts are not displaying i think that it is the problem with xml tags in php page. – ramsai Apr 20 '12 at 12:47
  • OK well it's good if there's no error, it means the data is probably coming out OK. Best thing to do now is update your question with your new issue, new code and any testing you've done. – Paystey Apr 20 '12 at 13:08
  • @paystay thank you very much for your help i got the result what i expect i just remove the mysql_free_result from the while loop. Thank you very much once again – ramsai Apr 23 '12 at 13:28
  • HAHA I completely missed that, too busy looking at the while looping over num_rows. Glad you got it working. – Paystey Apr 23 '12 at 14:29
1

Check a few more things:

a) The path to the SWF is correct.
b) FusionCharts.js is loaded in the page
c) print $strXML in a TEXTAREA to check whether proper XML is generated.

sudipto
  • 2,472
  • 1
  • 17
  • 21
  • hey i tried it but it is not giving any output just i am getting blank page. Thank you for your respose.Let me know if there were any debugging methods. – ramsai Apr 23 '12 at 09:06
  • when i try to print it out it is giving following message in the text area: – ramsai Apr 23 '12 at 09:20
  • thank you very much for your help i got the result what i expect i just remove the mysql_free_result from the while loop. Thank you very much once again – ramsai Apr 23 '12 at 13:28