【发布时间】:2015-01-12 11:36:54
【问题描述】:
我所做的只是将用户评分和评论保存到表中,然后从数据库中调用它。现在我要做的是添加所有评分(例如:5+4+3= 12),然后将它们除以评分数(12/3 = 4),得到平均评分或总评分。
我可以显示评论,但是如何将评分列中的所有值相加并获得平均值。
if (mysqli_num_rows($mesult) > 0) {
$count = mysqli_num_rows($mesult);
echo '<p class="">'.$count.' Reviews</p>';
while($row = mysqli_fetch_assoc($mesult)) {
$name =$row["name"];
$text =$row["text"];
$heading =$row["heading"];
$rating =$row["rating"];
echo '<div class="review" itemscope itemtype="http://schema.org/Review"> <meta itemprop="itemReviewed" content ="'.$title.'"/> <p class="heading"><strong>'.$heading.'</strong></p><div class="ratings" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"> <meta itemprop="worstRating" content = "1"/><span itemprop="ratingValue">'.$rating.'</span>/<span itemprop="bestRating">5</span></div><p class="reviewtext" itemprop="description">'.$text.'</p><div class="reviewby" itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">'.$name.'</span></div></div>';
}
我还要查询的是
$loutput ="SELECT * FROM rating
WHERE product=$ID";
$mesult = mysqli_query($conns,$loutput);
【问题讨论】: