etrader Posted January 19, 2011 Share Posted January 19, 2011 I have a string for rating, containing numbers from 0-5. How I can assign an image to each range: 0-0.5 displaying 05.jpg 0.5-1.0 displaying 10.jpg . . . 4.5-5.0 displaying 50.jpg Link to comment https://forums.phpfreaks.com/topic/224928-showing-images-for-rating/ Share on other sites More sharing options...
sasa Posted January 19, 2011 Share Posted January 19, 2011 if rating is 0.5 do you like to display 05.jpg or 10.jpg? <?php $test = .5; echo $im= sprintf('%02d.jpg', ceil($test*2)*5),"<br />\n"; echo $im= sprintf('%02d.jpg', (floor($test*2)+1)*5); ?> Link to comment https://forums.phpfreaks.com/topic/224928-showing-images-for-rating/#findComment-1161828 Share on other sites More sharing options...
etrader Posted January 19, 2011 Author Share Posted January 19, 2011 Thanks sasa, it works perfectly Definitely, I meant the first one, as the second one may lead to 5.5, which is indeed invalid. Thanks for your kind support Link to comment https://forums.phpfreaks.com/topic/224928-showing-images-for-rating/#findComment-1161845 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.