Dear Mr News:

On Fri, Jun 28, 2002 at 12:41:56PM -0700, wrote:
> I'd like to add all values for $purchase_price that are returned, 
> how do I do this?
> $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)) {
   $total = $total + $purchase_price;

That works if you want to process each row as you go along AND get a 
total.  You could also go straight for the total in the query if you 
don't need line by line processing:

SELECT sum(purchase_price) as totl FROM assets GROUP BY order_number
where order_number='$order_number';


               PHP classes that make web design easier
        SQL Solution  |   Layout Solution   |  Form Solution  | |
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY     v: 718-854-0335     f: 718-854-0409

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to