Forum Moderators: coopster
if (($StarRating =1) && ($StarRating <=1.99)){
$StarPicture = "1star.jpg";
if (($StarRating =2) && ($StarRating <=2.99)){
$StarPicture = "2star.jpg";
if (($StarRating =3) && ($StarRating <=3.99)){
$StarPicture = "3star.jpg";
if (($StarRating =4) && ($StarRating <=4.99)){
$StarPicture = "4star.jpg";
}else{
$StarPicture = "5star.jpg";
}
}
}
}
$star_rating = [url=http://uk2.php.net/manual/en/function.floor.php]floor[/url]($StarRating); // so 2.7 = 2. You may want [url=http://uk2.php.net/manual/en/function.ceil.php]ceil[/url] so that 2.7 = 3.
switch ($star_rating) {
case 1:
$StarPicture = "1star.jpg";
break
case 2:
$StarPicture = "2star.jpg";
break
case 3:
$StarPicture = "3star.jpg";
break
case 4:
$StarPicture = "4star.jpg";
break
case 5:
$StarPicture = "5star.jpg";
break;
default: // for testing, as this shouldnt ever be called
echo 'Something is wrong';
break;
}
$StarPicture=(($StarRating>5)?("5"):(floor($StarRating)))."star.jpg";
$StarPicture = (($StarRating == 5)?("5"):(floor($StarRating)))."star.jpg";
Sorry, im new!
$star_rating = floor($StarRating); // so 2.7 = 2. You may want ceil so that 2.7 = 3.
switch ($star_rating) {
case 1:
$StarPicture = "1star.jpg";
break
case 2:
$StarPicture = "2star.jpg";
break
case 3:
$StarPicture = "3star.jpg";
break
case 4:
$StarPicture = "4star.jpg";
break
case 5:
$StarPicture = "5star.jpg";
break;
default: // for testing, as this shouldnt ever be called
echo 'Something is wrong';
break;
}
Actually scrap that...You need to put; at the end of the breaks, as I forgot them. Sorry.
$star_rating = floor($StarRating); // so 2.7 = 2. You may want ceil so that 2.7 = 3.
switch ($star_rating) {
case 1:
$StarPicture = "1star.jpg";
break;
case 2:
$StarPicture = "2star.jpg";
break;
case 3:
$StarPicture = "3star.jpg";
break;
case 4:
$StarPicture = "4star.jpg";
break;
case 5:
$StarPicture = "5star.jpg";
break;
default: // for testing, as this shouldnt ever be called
echo 'Something is wrong';
break;
}
<edit>
You may be able to use $StarRating and be able to remove the $star_rating. I just put that other variable in there if you needed the original unaltered $StarRating later in your script.
[edited by: PHP_Chimp at 4:18 pm (utc) on Jan. 29, 2008]