variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

variables

Post 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.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post by smpdawg »

I think you are looking for GROUP BY and sum() in SQL.
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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.
User avatar
smpdawg
Forum Contributor
Posts: 292
Joined: Thu Jan 27, 2005 3:10 pm
Location: Houston, TX
Contact:

Post 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];
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

yes there is another loop but the array worked out. thanks
Post Reply