Page 1 of 1

variables

Posted: Sun Feb 27, 2005 8:14 pm
by shiznatix
My problem is...

Code: Select all

$rules = mysql_query("SELECT * FROM item_cat WHERE cid='$itm_cat'");
					while ($row3 = mysql_fetch_assoc($rules)){
					$qty = $rowї'qty'] + $qty;
						if ($qty > $row3ї'xShip_item']){
$qty continues to add to itself. But what I need is $qty to be diffrent for each $itm_cat. Is there any way that if $itm_cat = 'shirts' then $qty will add up for the shirts but when the $itm_cat comes through and is 'hats' then $qty will start adding up a new number. Its hard to explain if you don't understand Im sorry.

Posted: Sun Feb 27, 2005 8:36 pm
by smpdawg
I think you are looking for GROUP BY and sum() in SQL.

Posted: Sun Feb 27, 2005 8:48 pm
by shiznatix
no its not that, everything is working but i need a total of the amount of items for each $itm_cat that comes through the loop.

Posted: Sun Feb 27, 2005 9:15 pm
by smpdawg
How does $itm_cat change? Is there an outer loop that we aren't seeing?

Can't you create an array called $qty and use the $itm_cat as the index?

e.g.

Code: Select all

$qtyї$itm_cat] = $rowї'qty'] + $qtyї$itm_cat];

Posted: Sun Feb 27, 2005 9:22 pm
by shiznatix
yes there is another loop but the array worked out. thanks