3 ms·
Product Rating Script Using PHP
Creating a function to display a product ratings is trivial using PHP.
All you need is to decide on the values for you ratings and a the image to display for each rating.
For this Example we will use a system that stores ratings as descrete values and not continous values..............
- edw519 18y agoToo much code. Too many "if" statements that have to be executed every time. Try: <?php function getRatingImage($rating) { $vals = ['zero','half','one','one_half','two','two_half','three','three_half','four','four_half','five']; $ndx = intval($rating * 2); if($ndx > 10){$ndx = 10}; return "./" + $vals[$ndx] + ".jpg"; } ?>
- sanswork 18y agoI totally agree that the use of all those ifs is bad. That said a switch statement will be faster than the code you posted(Though you were thinking in another language when your wrote your snippit methinks) if speed is your concern.