MySQL table operations (multiply/divide)
Posted: Mon Jan 10, 2011 11:26 pm
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):
Here is how it displays:
http://componentadvice.com/category.php?id=1
Any ideas?
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>";http://componentadvice.com/category.php?id=1
Any ideas?