Page 1 of 1

MySQL table operations (multiply/divide)

Posted: Mon Jan 10, 2011 11:26 pm
by maxhudson
Basically, I have two colums.

What I want it to do is this:

if column (topic_rating_total)'s value = 0 {
$ratingtotal = "0" }
else {
$ratingtotal = column (topic_rating_total)'s value divided by column (topic_num_rating)'s value}

Heres my code attemt (snippet):

Code: Select all

while($row = mysql_fetch_assoc($result))
{				
if($row['topic_rating_total'] == 0){
$ratingtotal = "0";
} else {
$ratingtotal = ($row['topic_rating_total'] / $row['topic_num_ratings']);
}

echo "<td class='ratingcat' > $ratingtotal </td>";
Here is how it displays:

http://componentadvice.com/category.php?id=1

Any ideas?

Re: MySQL table operations (multiply/divide)

Posted: Tue Jan 11, 2011 4:08 am
by social_experiment
Move this code inside the else statement

Code: Select all

echo "<td class='ratingcat' > $ratingtotal </td>";