Page 1 of 1

how to display quantity of items in shopping cart

Posted: Sun Apr 24, 2011 10:08 am
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..

Re: how to display quantity of items in shopping cart

Posted: Sun Apr 24, 2011 7:45 pm
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()?