I have a table with ratings for every store in a directory. I want to display the average rating from each store on a business directory list page. I have the directory business listing page finished without the average rating.

I believe I have figured out how to create an average rating, but I don't know how to get the rating to output in the loop for each store.

Here is how I calculate the rating:

$result = mysql_query("SELECT AVG(rating) FROM reviews GROUP BY store_id WHERE store_id = '$storeid'");
$rating_for_page = mysql_fetch_row($result);
$rating = $rating_for_page[0];



Question: Should if/else statements be arranged by rareness of cases or difficulty of dealing with them?
Answer: Try to enhance readability.  One way is to place the longer code block into the else part.

if (s == null)
     // short code
else 
     // long 
     // code
     // block


is more readable than

if (s != null)
    // long
    // code
    // block
else
    // short code