-1

I have tried muiltiple strings of code to find the awswer please help me out, here's the code

    $rating = $row['rating_total'] / $row['number_ratings'];

if($rating < 2 && $rating => 1) {
$rating = ' <img src="rating.png" /> ';
  }

if($rating < 3 && $rating => 2) {
$rating = ' <img src="rating.png" /> <img src="rating.png" /> ';
  }

if($rating < 4) && ($rating => 3) {
$rating = ' <img src="rating.png" /> <img src="rating.png" /> <img src="rating.png" />'; 
  } 
  if($rating < 5) && ($rating => 4) {
$rating = ' <img src="rating.png" /> <img src="rating.png" /> <img src="rating.png" /> <img src="rating.png" />';
  }
   if($rating < 6) && ($rating => 5) {
$rating = ' <img src="rating.png" /> <img src="rating.png" /> <img src="rating.png" /> <img src="rating.png" /> <img src="rating.png" /> ';
  }
4

1 回答 1

0

让我们从你的代码开始,我同意其他人的观点,这是一个坏主意。无论如何,在使用 >/< 之前确保变量有整数,然后

$rating=intval($rating)

if($rating==1){$rating='<img src="" />'}
else if($rating==2){$rating='<img src="" /> <img src="" />'}
else if($rating==3){$rating='<img src="" /> <img src="" /> <img src="" />'}

首先还要确认您是在两个整数上执行 '/' 或浮动而不是两个字符串。

  $rating = floatval($row['rating_total']) / floatval($row['number_ratings']) ;

这可能是不必要的,但始终确定您是否必须找出问题所在

并尝试echo $rating在两者之间使用,看看出了什么问题。

于 2012-10-18T18:38:57.497 回答