Jump to content

Archived

This topic is now archived and is closed to further replies.

Cannibal_Monkey

Adding numbers in row

Recommended Posts

I have a row C of several numbers. I want to add all the numbers of that row and create a new variable. I have this for that line of code "$e = mysql_query('SELECT SUM `c` FROM `b`');" If it's wrong what do I do? I've searched around and couldn't find the answer.

Share this post


Link to post
Share on other sites
It's almost right:

[code]
<?php
$sql = "SELECT SUM(c) as total FROM tablename";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
echo "The total is {$row['total']}";
?>
[/code]

Regards
Huggie

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.