Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old September 9th, 2012, 07:27 AM
Registered User
Points: 55, Level: 1
Points: 55, Level: 1 Points: 55, Level: 1 Points: 55, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 09:03 AM



All times are GMT -4. The time now is 05:01 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.