[PHP] math calculations query

2001-04-26 Thread sean

hi all,

i have a script which selects description, price and quantity from a mysql
table.

i have displayed the results on a page in the form of description, price,
quantity but I was wondering how best to go about calculating a total total,
ie. sum of quantitys multiplied by sum of prices.

Any ideas?

Many thanks,

Sean.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] math calculations query

2001-04-26 Thread David VanHorn

At 08:31 PM 4/26/01 +0100, [EMAIL PROTECTED] wrote:
hi all,

i have a script which selects description, price and quantity from a mysql
table.

i have displayed the results on a page in the form of description, price,
quantity but I was wondering how best to go about calculating a total total,
ie. sum of quantitys multiplied by sum of prices.

Generally, that's not how you do that.
You'd calculate extended prices based on quantity of item and price, then 
add all extended prices.

1 Thingy  $5  Ext= $5
2 SuperThingy $3  Ext=$6

Total is $11

As opposed to
3 * $8 by the method you described.


--
Dave's Engineering Page: http://www.dvanhorn.org
Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] math calculations query

2001-04-26 Thread sean

oh, I am such a bone head.. but the actual question was how to calculate the
totals.

i have a column on my form that says $qry[price]*$qry[quantity] which
gives me a column of totals but my question is how to total that up???

any ideas?



David VanHorn [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 At 08:31 PM 4/26/01 +0100, [EMAIL PROTECTED] wrote:
 hi all,
 
 i have a script which selects description, price and quantity from a
mysql
 table.
 
 i have displayed the results on a page in the form of description, price,
 quantity but I was wondering how best to go about calculating a total
total,
 ie. sum of quantitys multiplied by sum of prices.

 Generally, that's not how you do that.
 You'd calculate extended prices based on quantity of item and price,
then
 add all extended prices.

 1 Thingy  $5  Ext= $5
 2 SuperThingy $3  Ext=$6

 Total is $11

 As opposed to
 3 * $8 by the method you described.


 --
 Dave's Engineering Page: http://www.dvanhorn.org
 Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] math calculations query

2001-04-26 Thread Jack Dempsey

initialize a total variable to 0. every time you print out a price, $total
+= $currentprice.
at the end you'll have the total. am i misunderstanding you?

-jack

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 26, 2001 3:43 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] math calculations query


oh, I am such a bone head.. but the actual question was how to calculate the
totals.

i have a column on my form that says $qry[price]*$qry[quantity] which
gives me a column of totals but my question is how to total that up???

any ideas?



David VanHorn [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 At 08:31 PM 4/26/01 +0100, [EMAIL PROTECTED] wrote:
 hi all,
 
 i have a script which selects description, price and quantity from a
mysql
 table.
 
 i have displayed the results on a page in the form of description, price,
 quantity but I was wondering how best to go about calculating a total
total,
 ie. sum of quantitys multiplied by sum of prices.

 Generally, that's not how you do that.
 You'd calculate extended prices based on quantity of item and price,
then
 add all extended prices.

 1 Thingy  $5  Ext= $5
 2 SuperThingy $3  Ext=$6

 Total is $11

 As opposed to
 3 * $8 by the method you described.


 --
 Dave's Engineering Page: http://www.dvanhorn.org
 Where's dave? http://www.findu.com/cgi-bin/find.cgi?kc6ete-9



 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] math calculations query

2001-04-26 Thread Maxim Maletsky



SELECT 
SUM(quantity)*SUM(total) As mySUM
FROM
table
WHERE
...


Sincerely, 

 Maxim Maletsky
 Founder, Chief Developer
 PHPBeginner.com (Where PHP Begins)
 [EMAIL PROTECTED]
 www.phpbeginner.com



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Friday, April 27, 2001 4:31 AM
To: [EMAIL PROTECTED]
Subject: [PHP] math calculations query


hi all,

i have a script which selects description, price and quantity from a mysql
table.

i have displayed the results on a page in the form of description, price,
quantity but I was wondering how best to go about calculating a total total,
ie. sum of quantitys multiplied by sum of prices.

Any ideas?

Many thanks,

Sean.





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] math calculations query

2001-04-26 Thread Steve Werby

Maxim Maletsky [EMAIL PROTECTED] wrote:
 SELECT
 SUM(quantity)*SUM(total) As mySUM
 FROM
 table
 WHERE

Technically, this is correct based on what the original poster (below)
stated he wanted, but that's not really what he wanted since there's no real
world reason to calculate what he stated he wanted.  He must really want the
total monetary value of the items returned by the query.  That's calculated
by multiplying the quantity of each record by the price of each item and
summing that for each record.  So the correct SQL statement is:

SELECT SUM(price*quantity)
FROM table_name
WHERE ...

If he doesn't want to run the query above in addition to his existing query
to return individual records, he can calculate this total programatically.
Sean, in this case, as you're looping through the records do:

$amount_record = $price * $quantity;
$amount_total += $amount_record;

After the loop is complete, $amount_total will contain the value you want.
Alternately, the first line can be eliminated by calculating the amount for
each record within the query.

[EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] wrote:
 i have a script which selects description, price and quantity from a mysql
 table.

 i have displayed the results on a page in the form of description, price,
 quantity but I was wondering how best to go about calculating a total
total,
 ie. sum of quantitys multiplied by sum of prices.

--
Steve Werby
President, Befriend Internet Services LLC
http://www.befriend.com/


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]