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 Quote 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); ?> Quote 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 Quote Link to comment https://forums.phpfreaks.com/topic/224928-showing-images-for-rating/#findComment-1161845 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.