Counting values
Moderator: General Moderators
Counting values
if you have a Mysql database stored with dollar values for example
58.20
100.12
15.00
25.35
what is the best to take this information and out put a total for example
58.20
100.12
15.00
25.35
the total is 198.67
again thanks for all your help you have given me!
58.20
100.12
15.00
25.35
what is the best to take this information and out put a total for example
58.20
100.12
15.00
25.35
the total is 198.67
again thanks for all your help you have given me!
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
Code: Select all
SELECT SUM(col_I_want_added) FROM table WHERE something = somethngelse-
thegreatone2176
- Forum Contributor
- Posts: 102
- Joined: Sun Jul 11, 2004 1:27 pm
you could do something like
Code: Select all
$link = "SELECT * FROM payments";
$result = mysql_query($link);
while ($row = mysql_fetch_row($result)){
$price = $rowїmoney];
$total += $price;
}
echo "The total is " . $total;- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Why would you want to loop through your database when yo ucan get it in one shotthegreatone2176 wrote:you could do something like
Code: Select all
$link = "SELECT * FROM payments"; $result = mysql_query($link); while ($row = mysql_fetch_row($result)){ $price = $rowїmoney]; $total += $price; } echo "The total is " . $total;
-
thegreatone2176
- Forum Contributor
- Posts: 102
- Joined: Sun Jul 11, 2004 1:27 pm
Code: Select all
$sql = mysql_query("SELECT SUM(amount) as total FROM billdata");
while ($row = mysql_fetch_array($sql)) {
echo $rowї'total'];
}the values im asking it to add for me are like this
100.23
56.43
23.00
etc
any ideas? thanks
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA