

Product Rating Script Using PHP - blackvine
http://www.xhydra.com/internet/product-rating-script-using-php.html
Creating a function to display a product ratings is trivial using PHP.<p>All you need is to decide on the values for you ratings and a the image to display for each rating.<p>For this Example we will use a system that stores ratings as descrete values and not continous values..............
======
edw519
Too 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
I 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.

