Welcome Guest, Not a member yet? Register   Sign In
Logical Problem With category and sub-category
#20

[eluser]brandingdavid[/eluser]
Okay, so it was your $this->db->where statement that wasn't working.
Changed to = $this->db->where('parent', $results[$x]['id']);

Tried this for my model:

Code:
<?php
class  Category  extends  Model {
    // Constructor
    function  __construct ()  {
        parent::Model();
        }

    function get_all ($parent=0)  {
        $this->db->where('parent', $parent);
        $query = $this->db->get('bin_location');
        $parents = $query->result_array();
        $results = array ();
        //print_r($parents);
        $x = 0;
        foreach ($parents as $parent) {
            $results[$x] = $parent;
            //echo $results[$x]['id'];
            $this->db->where('parent', $results[$x]['id']);
            $query = $this->db->get('bin_location');
            $results[$x]['children'] = $query->result_array();
            print_r ($results[$x]['children']);
            $x++;
       }
            //print_r($results[$x]);
        }
       // print_r($results);
    }

Got me part of the way there... already though I can see that it doesn't come back and do the third level. The children of children. Also, I can't get it to display. I get:

A PHP Error was encountered

Severity: Warning

Message: Invalid argument supplied for foreach()

Filename: views/frontpage_view.php

Line Number: 12

CODE USED: foreach ($categories as $category) {


Messages In This Thread
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 06:00 AM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 10:36 AM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 11:07 AM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 12:14 PM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 12:39 PM
Logical Problem With category and sub-category - by El Forum - 04-24-2009, 04:44 PM
Logical Problem With category and sub-category - by El Forum - 04-25-2009, 02:32 AM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 01:34 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 01:49 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 01:56 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:02 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:08 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:16 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:18 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:21 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:24 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 02:26 PM
Logical Problem With category and sub-category - by El Forum - 09-10-2009, 06:06 PM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 07:31 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 07:48 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 07:51 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 07:56 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 08:12 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 08:18 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 08:36 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 09:07 AM
Logical Problem With category and sub-category - by El Forum - 09-11-2009, 09:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB