2012-04-20 32 views
0

我想根據數據庫生成線圖。第一次我使用融合圖表時,我按照融合圖表文檔中動態圖表的步驟進行操作。這裏是我的PHP頁面代碼:圖不在php和mysql中生成融合圖

<?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是不是在C一個有效的MySQL結果資源:\ XAMPP \ htdocs中\ phpfusion \ ramfusion \ Chart.php在線28 圖表。 任何人都可以請幫我在這方面, 謝謝你在前進, Ramsai

回答

1

因爲你的過度的行數試圖環(6),而不是行本身。嘗試

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

而不是你的循環。這將返回一個關聯的行數組,然後將循環,將每行放入$row

+0

@ paystay,非常感謝您的回覆,我更改爲while($ row = mysql_fetch_assoc($ result)){ 但它仍然會拋出相同的錯誤。 – ramsai 2012-04-20 11:35:42

+0

你發佈的代碼是Chart.php吧?第28行是mysql_num_rows開啓的行,我建議改爲上面的行。如果這一切都是正確的你不應該得到這個錯誤仍然更新你的代碼在你的問題,我們會看看 – Paystey 2012-04-20 12:08:48

+0

現在我沒有得到任何錯誤,但PHP頁面不讀取XML標籤中的數據我認爲,我再次給我的修改chart.php頁面: – ramsai 2012-04-20 12:38:39

1

請檢查以下幾點:

a)SWF的路徑是正確的。
b)將FusionCharts.js加載到頁面
c)在TEXTAREA中打印$ strXML以檢查是否生成了正確的XML。

+0

嘿我試過了,但它沒有給出任何輸出,只是我得到空白頁面。感謝您的支持。讓我知道是否有任何調試方法。 – ramsai 2012-04-23 09:06:37

+0

當我嘗試打印出它在文本區域中給出以下消息: – ramsai 2012-04-23 09:20:37

+0

非常感謝您的幫助我得到了結果我期望我只是從while循環中刪除mysql_free_result。再次感謝你 – ramsai 2012-04-23 13:28:17