Getting total quantities

Getting total quantities

am 15.02.2010 05:55:11 von Karl DeSaulniers

--Apple-Mail-7-139702508
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

Hello List,
I have a situation where I want to figure out the total number of
products in my database.
I want to read all the fields $ProductStock and add them together to
get the TOTAL number of products, not just the number of rows in my
database.
Any pointers on the code to use for adding multiple rows field values?

EG:

Say I have three individual products and Product one has 10 and
Product 2 has 20 and Product three has 5, and these values are set in
the field $ProductStock, I want to get the result of 35 and not 3.

Any help is appreciated. TIA

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--Apple-Mail-7-139702508--

Re: Getting total quantities

am 15.02.2010 06:09:47 von Karl DeSaulniers

--Apple-Mail-8-140578830
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

Would it be?

$q = "SUM(ProductStock) FROM products";

or

$q = "SELECT SUM(ProductStock) AS ProductStock FROM products";

if I want to return $ProductStock as the value?

Karl



On Feb 14, 2010, at 10:55 PM, Karl DeSaulniers wrote:

> Hello List,
> I have a situation where I want to figure out the total number of
> products in my database.
> I want to read all the fields $ProductStock and add them together
> to get the TOTAL number of products, not just the number of rows in
> my database.
> Any pointers on the code to use for adding multiple rows field values?
>
> EG:
>
> Say I have three individual products and Product one has 10 and
> Product 2 has 20 and Product three has 5, and these values are set
> in the field $ProductStock, I want to get the result of 35 and not 3.
>
> Any help is appreciated. TIA
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--Apple-Mail-8-140578830--

Re: Getting total quantities

am 15.02.2010 06:20:07 von Chaitanya Yanamadala

--0015174c455c673e84047f9cc66a
Content-Type: text/plain; charset=UTF-8

Have you tried using it like this

*select count(*) from products;*


Chaitanya

"A man can get discouraged many times but he is not a failure until he stops
trying..."




On Mon, Feb 15, 2010 at 10:39 AM, Karl DeSaulniers wrote:

> Would it be?
>
> $q = "SUM(ProductStock) FROM products";
>
> or
>
> $q = "SELECT SUM(ProductStock) AS ProductStock FROM products";
>
> if I want to return $ProductStock as the value?
>
> Karl
>
>
>
>
> On Feb 14, 2010, at 10:55 PM, Karl DeSaulniers wrote:
>
> Hello List,
>> I have a situation where I want to figure out the total number of products
>> in my database.
>> I want to read all the fields $ProductStock and add them together to get
>> the TOTAL number of products, not just the number of rows in my database.
>> Any pointers on the code to use for adding multiple rows field values?
>>
>> EG:
>>
>> Say I have three individual products and Product one has 10 and Product 2
>> has 20 and Product three has 5, and these values are set in the field
>> $ProductStock, I want to get the result of 35 and not 3.
>>
>> Any help is appreciated. TIA
>>
>> Karl DeSaulniers
>> Design Drumm
>> http://designdrumm.com
>>
>>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>

--0015174c455c673e84047f9cc66a--

Re: Getting total quantities

am 15.02.2010 06:32:02 von dmagick

Karl DeSaulniers wrote:
> Would it be?
>
> $q = "SUM(ProductStock) FROM products";
>
> or
>
> $q = "SELECT SUM(ProductStock) AS ProductStock FROM products";
>
> if I want to return $ProductStock as the value?

This one.

The "AS" gives it an alias (or shortcut) to make it easier to find in
mysql_fetch_array etc.

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Getting total quantities

am 15.02.2010 06:32:25 von dmagick

Chaitanya Yanamadala wrote:
> Have you tried using it like this
>
> *select count(*) from products;*

This will give you the number of rows in the table, not what Karl wants.

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Getting total quantities

am 15.02.2010 06:34:30 von Chaitanya Yanamadala

--000e0cd1fb04d72b08047f9cf989
Content-Type: text/plain; charset=UTF-8

*Hai Chris
I already send him the right one. But my mail has been blocked by the php
lists. so i send a personal mail for him...
FYI....
SELECT SUM(ProductStock) FROM products;
*
if u want to give an other name for the row then use it as *


**
SELECT SUM(ProductStock) as stock FROM products;*

Chaitanya

"A man can get discouraged many times but he is not a failure until he stops
trying..."



On Mon, Feb 15, 2010 at 11:02 AM, Chris wrote:

> Karl DeSaulniers wrote:
>
>> Would it be?
>>
>> $q = "SUM(ProductStock) FROM products";
>>
>> or
>>
>> $q = "SELECT SUM(ProductStock) AS ProductStock FROM products";
>>
>> if I want to return $ProductStock as the value?
>>
>
> This one.
>
> The "AS" gives it an alias (or shortcut) to make it easier to find in
> mysql_fetch_array etc.
>
>
> --
> Postgresql & php tutorials
>
>
>

--000e0cd1fb04d72b08047f9cf989--

Re: Getting total quantities

am 15.02.2010 06:36:14 von Karl DeSaulniers

--Apple-Mail-12-142166216
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

Ok, sweet, then I am on the right track.
Now I did notice that I forgot the SELECT in the first query, does
that matter?
Can I just start out with SUM?
Thanks for your response.

Karl

On Feb 14, 2010, at 11:32 PM, Chris wrote:

> Karl DeSaulniers wrote:
>> Would it be?
>> $q = "SUM(ProductStock) FROM products";
>> or
>> $q = "SELECT SUM(ProductStock) AS ProductStock FROM products";
>> if I want to return $ProductStock as the value?
>
> This one.
>
> The "AS" gives it an alias (or shortcut) to make it easier to find
> in mysql_fetch_array etc.
>
> --
> Postgresql & php tutorials
> http://www.designmagick.com/
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--Apple-Mail-12-142166216--

Re: Getting total quantities

am 15.02.2010 06:43:41 von dmagick

Karl DeSaulniers wrote:
> Ok, sweet, then I am on the right track.
> Now I did notice that I forgot the SELECT in the first query, does that
> matter?
> Can I just start out with SUM?

No - that's invalid sql.

--
Postgresql & php tutorials
http://www.designmagick.com/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

php-db-unsubscribe@lists.php.net

am 16.02.2010 18:35:14 von Kevin Murphy

php-db-unsubscribe@lists.php.net

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php