How to count the number of PRODUCTS bought in a cart.
A shopping cart has a table called "cart" where the customer's selections are stored.
The customer buys 1 item of Product C, 2 items of Product H and 3 items of Product T.
I need to be able to count the number of PRODUCTS bought NOT the number of items. i.e. the answer here is 3.
What is the EASIEST way to do this?
Thanks.
It depends on your table structure, why don't you post it?
But the command you're looking for is something like
SELECT COUNT( DISTINCT *something* )
I thought about using the line below:
productqty int(3) NOT NULL default '1',
and then counting it somehow.
Will the following work?
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and productqty = $productqty" );
$item_result = mysql_query($result);
$item_count = mysql_result($item_result,0,"sum(productqty)" );
THE TABLE>>>>>>>>>>>>>>>>
$sql2 = ("CREATE TABLE cart (
cartId int(11) NOT NULL auto_increment,
cookieId varchar(50) default NULL,
itemId int(11) default NULL,
qty int(11) default NULL,
itemName varchar(50) default NULL,
productqty int(3) NOT NULL default '1',
PRIMARY KEY (cartId),
UNIQUE KEY id (cartId)
) TYPE=MyISAM;" );
SELECT COUNT( DISTINCT itemID ) FROM car WHERE cookieID = '" ... '" )
You don't necessarily need the distinct portion, but you can count the item IDs. Or heck, you can do select count( * ) and it will work, too.
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks