Reputation: 323
Please help me to solve this. As I am just in a learning phase of PHP/Mysql.
I have a php feedback form as a rating system from 1-5. You can find my form here http://innovatrix.co.in/feedback_priyajit/feedback%20form1.html
Every time a user provide feedback it saves form values into a mysql database. Below is my database structure.
Now I want to calculate average data of every row (like waiting) and show it on a php file as a graph and also separate graph for every option but on a same page.
I know I can use query SELECT AVG(waiting) FROM feedback
to get an average of "waiting"
But how can I do this for every options from a same file and also show it as a graph. Database will be updated frequently, thus it should reflect the graph also.
Please help me with a concept for achieving this.
Below is my php file which I am using to store form values into database.
<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>";
?>
Upvotes: 1
Views: 2036
Reputation: 96
If you want all the averages in one query, you can just delimit them with commas.
SELECT AVG(waiting), AVG(consultation), AVG(preoperative), AVG(specialists), ...... FROM feedback
If you want to know how to put them in a graph, take a look at one of the many jQuery graph or plot makers, like: http://www.jqplot.com/tests/bar-charts.php
Upvotes: 2