Ok so I have a bit of code.

echo "<span class='sortstyle'><strong>Average rating:</strong> ";
		while($row = mysql_fetch_array($result))
		{
			$rating1 += $row[rating1];
		}
		$avgrating = round($rating1/$numberofrows, 2);
		echo $avgrating." / 5</span><span class='sortstyle'><strong>Total reviews:</strong> ".$numberofrows."</span>";
	}

I want this to display the values from my database but from different rows so I tried.

echo "<span class='sortstyle'><strong>Average rating:</strong> ";
		while($row = mysql_fetch_array($result))
		{
			$rating1 += $row[rating1];
		}
		$avgrating = round($rating1/$numberofrows, 2);
		echo $avgrating." / 5</span><span class='sortstyle'><strong>Total reviews:</strong> ".$numberofrows."</span>";
	}{
	echo "<span class='sortstyle'><strong>Average rating:</strong> ";
		while($row = mysql_fetch_array($result))
		{
			$rating += $row[rating];
		}
		$avgrating = round($rating/$numberofrows, 2);
		echo $avgrating." / 5</span><span class='sortstyle'><strong>Total reviews:</strong> ".$numberofrows."</span>";
		}

When I try it this way it displays a zero but if I change the second to a rating1 it displays correctly but it shows the same values as the first.
How can I get this to work right?

What I want it to do is each area displays the rating percentage based on the sql information.

Thank you.

Ideally you sure have your sql do what you want.


however, to keep things moving forward and help you do this in a slightly more MVC approach......


Load the results of your mysql_fetch_array($result) into an array.

then do a foreach on the array. Then you can control where you do your breaks and sums.

something along the lines of

$ratingarray = array();
while($row = mysql_fetch_array($result))
{
   $ratingarray[] = $row;
}
foreach($ratingarray as $thisrating)
{
  //put logic here to separate them out or alter original array
}
//then display your results how you want here, with another for loop.