Re: Help adding variables from MySQL query
| From: | Richard Lynch | Date: | Sun, 30 Jun 2002 22:31:22 +0000 |
| Subject: | Re: Help adding variables from MySQL query | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-104779@lists.php.net to get a copy of this message | ||
>I'd like to add all values for $purchase_price that are returned, how do I
>do this?
>Here's what i have now.
><?php
>$result = mysql_query("SELECT purchase_price FROM assets where
>order_number='$order_number' ORDER BY $desc");
$total = 0;
>while(list($purchase_price) = mysql_fetch_row($result)) {
echo "$purchase_price<BR>\n";
$total += $purchase_price; # Short-hand for $total = $total +
$purchase_price;
}
>?>
Actually, it might be better to just change your SQL to:
select SUM(purchase_price) from assets where order_number = '$order_number'
The SQL SUM() will be *MUCH* faster than your while () loop.
--
Like Music? http://l-i-e.com/artists.htm