是否有适当的方法来做到这一点。我想计算一个表的平均评分并同时更新另一个表中的结果。我是 PHP 和 MYSQL 的新手,我将不胜感激
$query=mysql_query("INSERT INTO review (username, restaurant, rating, review) VALUES ('$username','$restaurant','$rating','$review')");
if($query)
{
$avg_query="SELECT ROUND(AVG(rating),0) FROM review WHERE name =\"$restaurant\"";
$avg_result=mysql_query($avg_query);
$avg_row=mysql_fetch_array($avg_result);
$rating=$row['ROUND(AVG(rating),0)'];
if($avg_result)
{
$update_query= "UPDATE restaurant SET rating=\"$rating\" WHERE name =\"$restaurant\"";
$update_result=mysql_query($update_query);
}
}
else
{
}
谢谢!