Wrox Programmer Forums
|
BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
This is the forum to discuss the Wrox book Professional CodeIgniter by Thomas Myer; ISBN: 9780470282458
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 9th, 2012, 07:27 AM
Registered User
 
Join Date: Sep 2012
Posts: 9
Thanks: 0
Thanked 3 Times in 3 Posts
Default Total Cart Count of Items

Does anyone know how to get the total items in the cart?

I have tried everything and the result is always 0
/****************************/
After what seemed like many hours, I finally solved my issue.

For those wanting to use this, here is what I did:

In my model I created a function taking information from the $_SESSION['cart']
Code:
function allCartItems() {
	$sessioncart = $_SESSION['cart'];/* store multi-dimensional array of shopping cart */
	$items = array();

	/* save each array key as a value, in our case we want just the total count of each item in the cart */
	foreach($sessioncart as $cartitems) {
		$items[] = $cartitems['count'];
	}		
	$total = 0; /* reset variable total */

	/* add together each item row's total item count */
	foreach (array_filter($items) as $value) {
		$total += $value;
	}

	/* display total items in the shopping cart */
	echo $total;
}
Then in the View where you want the result displayed, call the function
Code:
$this->MOrders->allCartItems();

Last edited by plavalle; September 10th, 2012 at 06:44 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem With Total in the Shopping Cart learningASP.Net BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 1 October 27th, 2007 09:33 AM
Ch15 - $total of cart how do i send 2 other page esuk BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 April 20th, 2006 07:02 PM
Getting Total Page Count eman2a Crystal Reports 0 August 11th, 2004 10:53 AM
Sub Total, Count discriminating dkaco BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 0 July 23rd, 2004 12:04 PM
total of items in my basket Ashleek007 Classic ASP Basics 1 January 29th, 2004 10:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.