From: Karl DeSaulniers on 14 Feb 2010 23:55 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
From: Karl DeSaulniers on 15 Feb 2010 00:09 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
From: Chaitanya Yanamadala on 15 Feb 2010 00:20 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 <karl(a)designdrumm.com>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 > >
From: Chris on 15 Feb 2010 00:32 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/
From: Chris on 15 Feb 2010 00:32
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/ |