how to display quantity of items in shopping cart

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
liyun88
Forum Commoner
Posts: 51
Joined: Thu Mar 31, 2011 12:18 pm

how to display quantity of items in shopping cart

Post by liyun88 »

hi,i face some problem to display quantity of item in shopping cart..this is my error Warning: explode() expects parameter 2 to be string, array given in

Code: Select all

function writeShoppingCart() {
	$cartid = $_SESSION['cartid'];
	if (!$cartid) {
		return '<p>You have no items in your shopping cart.</p>';
	} else {
		// Parse the cart session variable
		$items = explode(',',$cartid);
		$s = (count($items) > 1) ? 's':'';
		return '<p>You have <a href="viewCart.php">'.count($items).' item'.$s.' in your shopping cart.</a></p>';
	}
}
can anyone help me??thanks in advance..
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: how to display quantity of items in shopping cart

Post by superdezign »

The error says that $cartid is an array. Are you sure that you didn't mean to use sizeof() or count() instead of explode()?
Post Reply