4
There’s a way to improve this code ?
<?php
if ($calculation >= 5)
{
for ($i=1;$i<=5;$i++)
{
echo '<img src="'.$linkSite.'/img/star1_16x16.png"> ';
}
}
elseif ($calculation >=3 && $calculation <5)
{
for ($i=1;$i<=$calculation;$i++)
{
echo '<img src="'.$linkSite.'/img/star1_16x16.png"> ';
}
for ($calculation;$calculation<5;$calculation++)
{
echo '<img src="'.$linkSite.'/img/star_16x16.png"> ';
}
}
elseif ($calculation <=2)
{
for ($i=1;$i<=$calculation;$i++)
{
echo '<img src="'.$linkSite.'/img/star1_16x16.png"> ';
}
for ($calculation;$calculation<5;$calculation++)
{
echo '<img src="'.$linkSite.'/img/star_16x16.png"> ';
}
}
else
{
echo '<img src="'.$linkSite.'/img/star_16x16.png"> ';
}
?>
What’s ifs for? What does it change if it’s 5 or if it’s two? I think that’s all it takes:
for ($i=1;$i<=5;$i++) echo '<img src="'.$linkSite.'/img/star'.($i>$calculation?'1':'').'_16x16.png">';
– Bacco
Yes it is possible, believe me!
– rray
I suggest doing javascript and css because it is something visual that does not need to be processed on the server. Unless you have a very specific reason for rendering on the server. Take an example: http://stackoverflow.com/questions/1987524/turn-a-number-into-star-rating-display-using-jquery-and-css/1987545#1987545
– Daniel Omine
Actually, this is a case for pure CSS, and only change the class by PHP.
– Bacco
@Bacco Thanks!!
– William Alvares
@Danielomine I’ll try this there, it looks like it will make the system better :D
– William Alvares