php - 计算 php 中的平均评分

标签 php mysql

我有一个反馈表(评级 1-5),它将其值保存到 mysql 中。

现在请帮我找出要执行的 php 代码,该代码将从数据库中获取当前年份/月份的所有评级,将它们相加,然后进行平均计算。然后它将以图表的形式显示该值。

谢谢。

这是我的反馈表 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>

这是我的 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>";
?> 

最佳答案

关于php - 计算 php 中的平均评分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17957703/

相关文章:

php - MySQL 如果值为空则不搜索

php - 我如何检查我的服务器上是否安装了 PEAR?

php - laravel 登录 View 不执行任何操作

php - 如何查找具有一系列子值的零件号字符串?

php - Joomla 初始加载缓慢,调试开启

c# - 无法使用 mySql 在 Entity Frameworking 中使用 Decimal DataType 更新行

php - Web 表单正在向数据库提交空白数据

php - 在一个 API 请求中包含多个联接的单个查询,还是在单独的 API 请求中包含一些联接的几个查询?

php - 以表格形式显示插入数据库的数据

php - 分成两个变量?