I need to get the total from an array of $$ amounts contained in a mysql query. I know I need to use a loop to do it, but I can't figure out exactly how to implement it.
The field sprice contains the amount that I want added up. Basically, it's a very simple shopping cart.
<?php
$sum = mysql_query ("select sprice from sell_quote where orderid = '$cartid' and complete = -1");
if ($row1 = mysql_fetch_array($sum)){
$sprice = $row1["sprice"];
}
?>'
Any help will be greatly appreciated,
Dan
Recycle Video Games Network
Stupidity killed the cat, curiosity was framed!






Mark Hensler posted this at 17:48 — 3rd March 2001.
He has: 4,044 posts
Joined: Aug 2000
just add all the sprices, right?
<?php$total = 0;
$sum = mysql_query ("select sprice from sell_quote where orderid = '$cartid' and complete = -1");
if ($row1 = mysql_fetch_array($sum)){
$sprice = $row1["sprice"];
$total += $sprice;
}
?>
'
Mark Hensler ["Max Albert"] [Email]
If there is no answer on Google, then there is no question.
cds posted this at 16:35 — 4th March 2001.
They have: 359 posts
Joined: Mar 1999
Thanks Mark,
Got me started in the right direction anyway. As was listed above, it would only return the first $sprice in $total.
After consulting the PHP manual "again", it occurred to me that with the 'if' statement, it really wasn't creating a loop. Changing the 'if' to 'while' fixed the problem and life is good and I like computers again.
Dan
Recycle Video Games Network
Stupidity killed the cat, curiosity was framed!
Mark Hensler posted this at 07:21 — 5th March 2001.
He has: 4,044 posts
Joined: Aug 2000
sorry I missed that..
cds posted this at 15:44 — 5th March 2001.
They have: 359 posts
Joined: Mar 1999
You can stop beating your face on your desk. I think the World has enough Bulldogs.
Although, if you feel it is necessary and want to feel like you have accomplished something at the same time, I would recommend chasing parked cars.
Dan
Recycle Video Games Network
Stupidity killed the cat, curiosity was framed!