Reputation: 13
I have a small script, I have it adding up all of the number in a MYSQL column and echoing the result. I am trying to take the sum or echoed number and multiply it by 100. I can't seem to get it to echo the multiplication.
Here is the code i am using. Any help would be great, Thanks in advance.
//connect to db
$q = mysql_query("SELECT SUM(oil_production) as sum FROM wp_wct3 WHERE oil_production > 0") or die(mysql_error());
$row = mysql_fetch_assoc($q);
echo $row['sum']; echo " BOM"
echo $total = ($result['sum'] * 100);
?>
Upvotes: 0
Views: 670
Reputation: 12508
UPDATED ANSWER
echo $row['sum']; echo " BOM" ;
echo "Monthly Income based on $100 Oil = $";
echo "<span style=\"color:#00ff00\">";
echo $total = ($row['sum'] * 100);
echo "</span>";
?>
EDIT -
ONCE You're referring the array of results as rows[]
and once as results[]
... this it the error...
Upvotes: 2
Reputation: 1994
echo in your case will out the result of the assignment, which is "true" if assigned.
Assign it to $total, then echo $total:
$total = $result['sum'] * 100; echo $total;
Cheers,
Dan
Upvotes: 0
Reputation: 7804
Its should be. You wrote $result
instead of $row
echo $total = ($row['sum'] * 100);
Upvotes: 0