Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The first thing I would do is get rid of all those IF statements for the stars, either using an array for them or a switch statement, either of which would reduce the processing required for your script. An array would be my approach. Your code would look something like the following:</p> <pre><code>function ratingDetails($uid, $align, $width) { </code></pre> <p>$queryFull = "SELECT * FROM rating WHERE uid = $uid"; $resultFull = mysql_query($queryFull);</p> <p>// Declare the array for the stars. $astars = array( 0=> "notYet.jpg", 1=> "starOne.jpg", 1.5=> "starOneHalf.jpg", 2=> "starTwo.jpg", 2.5=> "starTwoHalf.jpg", 3=> "starThree.jpg", 3.5=> "starThreeHalf.jpg", 4=> "starFour.jpg", 4.5=> "starFourHalf.jpg", 5=> "starFive.jpg" );</p> <pre><code> //START DISPLAY TABLE IF RESULTS if(mysql_num_rows($resultFull) &gt; 0) { echo "&lt;table class=\"ratingTable\" align=\"center\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\" width=\"550\"&gt;\n"; echo "&lt;tr bgcolor=\"#6699cc\"&gt;&lt;th&gt;STARS&lt;/th&gt;&lt;th&gt;DATE RATED&lt;/th&gt;&lt;th&gt;COMMENT&lt;/th&gt;&lt;th&gt;RATED BY&lt;/th&gt;&lt;/tr&gt;\n"; while($rowFull = mysql_fetch_array($resultFull)) { $rating = $rowFull['rating']; $comment = $rowFull['comment']; $datePosted = date("M j, Y", $rowFull['date']); $rid = $rowFull['raterID']; $rater = getUsername($rid); $stars = $astars[$rating]; //DISPLAY IT ALL echo "&lt;tr&gt;&lt;td width=\"10\"&gt;&lt;img src=\"/images/rating/$stars\" width=\"105\" height=\"20\" /&gt;&lt;/td&gt;"; echo "&lt;td width=\"75\" align=\"center\"&gt;$datePosted&lt;/td&gt;&lt;td&gt;$comment&lt;/td&gt;&lt;td width=\"85\"&gt;$rater&lt;/td&gt;&lt;/tr&gt;\n"; }//END WHILE echo "&lt;/table&gt;\n"; } //END IF else { echo "&lt;table class=\"ratingTable\" align=\"center\" border=\"1\" cellspacing=\"0\" cellpadding=\"8\" width=\"550\"&gt;\n"; echo "&lt;tr&gt;&lt;td align=\"center\"&gt;&lt;span class=\"blue\"&gt;NO REVIEWS OR RATINGS FOR THIS DISTRIBUTOR&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;\n"; } //END IF ELSE </code></pre> <p>The decimals may cause a problem in the array; if so, you can enclose the keys in quotes; e.g., <code>"1.5"=&gt;"starOneHalf.jpg"</code></p> <p>The other thing you could do is create a variable for the HTML output instead of echoing the output every line, and then just echo the output at the end.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload