1

I have a feedback form (rating 1-5) which save its values into mysql.

Now please help me out with which php code to execute that will take all the rating in the current year/month from the database , sum them, and do the average calculation. Then it will show the value as a graph.

Thanks.

this is my feedback form html

<body>
<form id="form1" name="form1" method="post" action="process.php"  style="border:1px #CCCCCC solid; width:720px; margin:0 auto; padding:10px;">
<table width="700" align="center" cellpadding="0" cellspacing="0"  >

                      <tbody>
<tr><td valign="top"><strong>How would you evaluate the waiting before the procedures in our areas ?</strong>

  <label>
   <p>

    <input type="radio" name="radio1" id="radio1" value="1" />
    <input type="radio" name="radio1" id="radio1" value="2" />
    <input type="radio" name="radio1" id="radio1" value="3" />
    <input type="radio" name="radio1" id="radio1" value="4" />
    <input type="radio" name="radio1" id="radio1" value="5" />
       <br />
  </p>
  </label></td></tr><tr><td valign="top"><strong>How would you evaluate your consultation with the medical team prior to the procedure ?</strong>

  <label>
   <p>

    <input type="radio" name="radio2" id="radio2" value="1" />
    <input type="radio" name="radio2" id="radio2" value="2" />
    <input type="radio" name="radio2" id="radio2" value="3" />
    <input type="radio" name="radio2" id="radio2" value="4" />
    <input type="radio" name="radio2" id="radio2" value="5" />
       <br />
  </p>
  </label></td></tr><tr><td valign="top"><strong>How would you evaluate the pre- operative procedures (changing rooms, hair wash, haircut, etc) assisted by our Certified assistants / technicians prior to your procedure ?</strong>
  <label>
   <p>

    <input type="radio" name="radio3" id="radio3" value="1" />
    <input type="radio" name="radio3" id="radio3" value="2" />
    <input type="radio" name="radio3" id="radio3" value="3" />
    <input type="radio" name="radio3" id="radio3" value="4" />
    <input type="radio" name="radio3" id="radio3" value="5" />
       <br />
  </p>
  </label></td></tr><tr><td valign="top"><strong>How would you evaluate the procedure in terms of DHI Certified specialists' behavior ?</strong>

  <label>
   <p>

    <input type="radio" name="radio4" id="radio4" value="1" />
    <input type="radio" name="radio4" id="radio4" value="2" />
    <input type="radio" name="radio4" id="radio4" value="3" />
    <input type="radio" name="radio4" id="radio4" value="4" />
    <input type="radio" name="radio4" id="radio4" value="5" />
       <br />
  </p>
  </label></td></tr><tr><td valign="top"><strong>How would you evaluate the procedure in terms of DHI Certified Assistants' behavior ?</strong>

  <label>
   <p>

    <input type="radio" name="radio5" id="radio5" value="1" />
    <input type="radio" name="radio5" id="radio5" value="2" />
    <input type="radio" name="radio5" id="radio5" value="3" />
    <input type="radio" name="radio5" id="radio5" value="4" />
    <input type="radio" name="radio5" id="radio5" value="5" />
       <br />
  </p>
  </label></td></tr><tr><td valign="top"><strong>Did you find the procedure painful ?</strong>

  <label>
   <p>

    <input type="radio" name="radio6" id="radio6" value="1" />
    <input type="radio" name="radio6" id="radio6" value="2" />
    <input type="radio" name="radio6" id="radio6" value="3" />
    <input type="radio" name="radio6" id="radio6" value="4" />
    <input type="radio" name="radio6" id="radio6" value="5" />
       <br />
  </p>
  </label></td></tr><tr><td valign="top"><strong>How would you rate the operation room facilities (cleanliness, music, TV, comfort etc) ?</strong>

  <label>
   <p>

    <input type="radio" name="radio7" id="radio7" value="1" />
    <input type="radio" name="radio7" id="radio7" value="2" />
    <input type="radio" name="radio7" id="radio7" value="3" />
    <input type="radio" name="radio7" id="radio7" value="4" />
    <input type="radio" name="radio7" id="radio7" value="5" />
       <br />
  </p>
  </label></td></tr><tr><td valign="top"><strong>What are your first thoughts on the design & the distribution of the implanted hairs?</strong>

  <label>
   <p>

    <input type="radio" name="radio8" id="radio8" value="1" />
    <input type="radio" name="radio8" id="radio8" value="2" />
    <input type="radio" name="radio8" id="radio8" value="3" />
    <input type="radio" name="radio8" id="radio8" value="4" />
    <input type="radio" name="radio8" id="radio8" value="5" />
       <br />
  </p>
  </label></td></tr><tr><td valign="top"><strong>Would you recommend DHI to a frend of yours ?</strong>

  <label>
   <p>

    <input type="radio" name="radio9" id="radio9" value="yes" />
    <input type="radio" name="radio9" id="radio9" value="no" />

       <br />
  </p>
  </label></td></tr>
  <tr><td><strong> Suggestions</strong>
  <label>
  <p>
    <textarea name="suggestions" cols="50" rows="10" id="suggestions"></textarea>
  </p>
  <p>
    <label>
      <input type="submit" name="submit" id="submit" value="Submit" />
    </label>
    <label>
      <input type="reset" name="reset" id="reset" value="Reset" />
    </label>
  </p>
  </label></td></tr></tbody></table>

</form>

</body>
</html>

This is my php

<?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>";
?> 
PeeJay
  • 323
  • 4
  • 16
  • 4
    [Please, don't use `mysql_*` functions in new code](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [red box](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). **You also wide open to [SQL injections](http://stackoverflow.com/q/60174)** – John Conde Jul 30 '13 at 21:28
  • 1
    [MySQL AVG() function](http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html#function_avg) – Mark Baker Jul 30 '13 at 21:28
  • to get the average rating of waiting from feedback table I am using SELECT AVG( waiting ) FROM feedback;. It returns correct average. Now how can I display it as graph on a separate php file. @JohnnyFaldo – PeeJay Jul 30 '13 at 22:04

1 Answers1

0

It sounds like you want to use the AVG()

http://dev.mysql.com/doc/refman/5.6/en/group-by-functions.html#function_avg

Robadob
  • 5,319
  • 2
  • 23
  • 32
  • to get the average rating of waiting from feedback table I am using SELECT AVG( waiting ) FROM feedback;. It returns correct average. Now how can I display it as graph on a separate php file. – PeeJay Jul 30 '13 at 22:07
  • Once you have the output from your SQL query, run a loop and echo your results – aashnisshah Jul 30 '13 at 22:37