2013-07-31 60 views
1

請幫我解決這個問題。因爲我只是處於PHP/Mysql的學習階段。從mysql計算平均評分並將其顯示爲圖

我有一個php反饋表格作爲評分系統從1-5。你可以在這裏找到我的表格http://innovatrix.co.in/feedback_priyajit/feedback%20form1.html

每當用戶提供反饋,它將表單值保存到mysql數據庫中。以下是我的數據庫結構。

enter image description here

現在我想計算每一行的平均數據(如等待),並顯示在一個PHP文件爲曲線圖也每一個選項,但在同一頁上的單獨的圖形。

我知道我可以使用查詢SELECT AVG(waiting) FROM feedback獲得的「等待

平均,但我怎麼能做到這一點從同一個文件中的每個選項,也顯示出它作爲一個圖形。數據庫會經常更新,因此它也應該反映圖表。

請幫助我實現這一目標。

下面是我用來將表單值存儲到數據庫中的php文件。

<title>process</title> 
<?php 
$host="localhost"; 
$user_name="pramir_feedback"; 
$pwd="feedback"; 
$database_name="pramir_feedback"; 
$db=mysql_connect($host, $user_name, $pwd); 
if (mysql_error() > "") print mysql_error() . "<br>"; 
mysql_select_db($database_name, $db); 
if (mysql_error() > "") print mysql_error() . "<br>"; 
$waiting = $_POST['radio1']; 
$consultation = $_POST['radio2']; 
$preoperative = $_POST['radio3']; 
$specialists = $_POST['radio4']; 
$assistants = $_POST['radio5']; 
$painful = $_POST['radio6']; 
$operatingroom = $_POST['radio7']; 
$thought = $_POST['radio8']; 
$recommend = $_POST['radio9']; 
$suggestions = $_POST['suggestions']; 
$query = "insert into feedback (waiting, consultation, preoperative, specialists, assistants, painful, operatingroom, thought, recommend, suggestions) values ('" . $waiting . "', '" . $consultation . "', '" . $preoperative . "', '" . $specialists . "', '" . $assistants . "', '" . $painful . "', '" . $operatingroom . "', '" . $thought . "', '" . $recommend . "', '" . $suggestions . "')"; 
if (mysql_error() > "") print mysql_error() . "<br>"; 
$qresult = mysql_query($query); 
echo "<h1>Thank you for submitting your details!</h1>"; 
?> 

回答

2

如果你想在一個查詢中的所有均線,你可以用逗號分隔。

SELECT AVG(waiting), AVG(consultation), AVG(preoperative), AVG(specialists), ...... FROM feedback 

如果你想知道如何把它們放在一個圖表,看看很多jQuery的圖形或情節制造商之一,如:http://www.jqplot.com/tests/bar-charts.php