我想計算所有標題的平均評分。我有一個人下6個標題,每個人有5個星。我想顯示在所有等級(如4.2或4)如何計算星的平均評分
這裏是我的代碼
<li><p>Overall Experience</p>
<?php
$starsLeft = 5 - $count_all_guest_star[0]->overall_experience_star;
if($count_all_guest_star[0]->overall_experience_star>0):
for($i=1; $i<= $count_all_guest_star[0]->overall_experience_star; $i++)
{ ?>
<img src="<?php echo base_url(); ?>assets/img/on-stars.gif"/>
<?php
}
endif;
if ($starsLeft > 0) { // if there are any more stars left
for ($i = 1; $i <= $starsLeft; $i++) { // go through each remaining star
// show it empty
?>
<img src="<?php echo base_url(); ?>assets/img/off-stars.gif"/>
<?php }
}
?>
</li>
<li><p>Communication</p>
<?php
$com_starsLeft = 5 - $count_all_guest_star[0]->communication_star;
if($count_all_guest_star[0]->communication_star > 0):
for($j=1; $j<= $count_all_guest_star[0]->communication_star; $j++)
{
?>
<img src="<?php echo base_url(); ?>assets/img/on-stars.gif"/>
<?php
}
endif;
if ($com_starsLeft > 0) { // if there are any more stars left
for ($i = 1; $i <= $com_starsLeft; $i++) { // go through each remaining star
// show it empty
?>
<img src="<?php echo base_url(); ?>assets/img/off-stars.gif"/>
<?php }
}
?></li>
$AverageRating = ((1*$starsLeft)+(2*$com_starsLeft)+(3*$acc_starsLeft)+(4*$clean_starsLeft)+(5*$pick_starsLeft) + (6*$pick_starsLeft))/6;
echo '$AverageRating';
好心建議我任何解決方案。
我想這應該在數學 – SuperDJ
放在你什麼你的說法意思? – sleekdev
我已經更新了我的代碼友善地建議我任何解決方案。 – sleekdev