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 October 5th, 2009, 12:03 AM
Authorized User
 
Join Date: Sep 2009
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default Display categories and subcategories

Hi all,i'm trying to display the categories and the subcategories like this on the admin product page category dropdown

clothes
--shoes
--shirts
etc.
fun
--toys
--games

also the parent cannot be choosed..What should i do to achieve it?Thanks...
 
Old October 6th, 2009, 07:02 PM
Wrox Author
 
Join Date: May 2008
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default hmmmmmm.....

look in the mcats model...there should be a function called getCategoriesNav()...I think this grabs all the categories and builds a multidimensional array that you can process....I think that's right. I'm on my way out the door so I may be smokin' the hookah again. :)


Code:
function getCategoriesNav(){
     $data = array();
     $this->db->select('id,name,parentid');
     $this->db->where('status', 'active');
     $this->db->orderby('parentid','asc');
     $this->db->orderby('name','asc');
     $this->db->groupby('parentid,id');
     $Q = $this->db->get('categories');
     if ($Q->num_rows() > 0){
       foreach ($Q->result() as $row){
			if ($row->parentid > 0){
				$data[0][$row->parentid]['children'][$row->id] = $row->name;
			
			}else{
				$data[0][$row->id]['name'] = $row->name;
			}
		}
    }
    $Q->free_result(); 
    return $data; 
 }
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
The Following User Says Thank You to myerman For This Useful Post:
handoyo (October 6th, 2009)
 
Old October 6th, 2009, 11:46 PM
Authorized User
 
Join Date: Sep 2009
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default Thanks

Thanks myerman..By the way,how to change it to so i can use it to dropdown?

Last edited by handoyo; October 7th, 2009 at 12:11 AM..
 
Old October 7th, 2009, 08:04 AM
Wrox Author
 
Join Date: May 2008
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default in the same model....

In the same model there is a function called getCategoriesDropDown() which should do what you're describing.

Code:
 function getCategoriesDropDown(){
     $data = array();
     $this->db->select('id,name');
     $this->db->where('parentid !=',0);
     $Q = $this->db->get('categories');
     if ($Q->num_rows() > 0){
       foreach ($Q->result_array() as $row){
         $data[$row['id']] = $row['name'];
       }
    }
    $Q->free_result();  
    return $data; 
 }
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
 
Old October 7th, 2009, 08:35 AM
Authorized User
 
Join Date: Sep 2009
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Is'n it the same with the default one on admin/products/create controller?Thanks..
 
Old October 7th, 2009, 08:42 AM
Wrox Author
 
Join Date: May 2008
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default on the create() function?

No, that one calls the addProduct() function over in MProducts model
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
 
Old October 7th, 2009, 11:35 AM
Authorized User
 
Join Date: Sep 2009
Posts: 22
Thanks: 2
Thanked 0 Times in 0 Posts
Default I'll try it

I'll try it myerman..Thanks..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Where does the values of $categories came from handoyo BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 2 September 28th, 2009 09:06 AM
creating sub categories? melkin Classic ASP Professional 1 August 30th, 2009 11:17 AM
Sub Categories for Forum- tectrix BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 9 May 21st, 2008 05:25 PM
Unlimited categories golden_drifter Access 2 August 31st, 2006 07:21 AM
Category SubCategories and two MySQL tables cjp_qld PHP Databases 2 August 29th, 2004 04:14 AM





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