duanmu6231 2014-08-05 18:55
浏览 28

PHP初学者与MySQL的麻烦

I am creating a website in which users can log on and review Tablet PC's On tablet page visitors to the site can see the reviews left by other users. Despite users being able to review 5 tablets, the 'ipad' page for example will only show 'ipad' review. The code can be seen below:

<?php
include('connection.php');
$result = mysql_query("SELECT * FROM tt_review WHERE product = 'Apple iPad'"); 

echo "<table border='1'>
<tr>

</tr>";

while($row = mysql_fetch_array($result)) //This function is calling the results variable and displaying them within the rows below
{
echo "<tr>"; //this code tells the page to output the table rows that are defined above
echo "<td>" . $row['name'] . "</td>";  
echo "<td>" . $row['date'] . "</td>"; //each row is then executed using the table data function
echo "<td>" . $row['product'] . "</td>";
echo "<td>" . $row['star'] . "</td>";
echo "<td>" . $row['comment'] . "</td>";

echo "</tr>";
}
echo "</table>";

?>

I have a field in my database called 'star' which is the rating the users have gave the tablet. 1, 2, 3, 4 or 5 are the options. I need code that works out the average of the 'star' rating from the 'ipad' page and to display an image based on whatever number it is.

All help is greatly appreciated as I am a newcomer and cant seem to find the answer online. Thanks Jonathan

  • 写回答

5条回答 默认 最新

  • dqby43944 2014-08-05 19:05
    关注

    From what I understand you want to calculate the average rating for each tablet. If yes, you can just fetch the star column for the particular tablet from the database and extract it as an array and run a simple for-each loop to calculate the sum and average of the rating for that tablet and based on the average it calculated, an indication can be placed on the screen in the form of images or something else.

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序