[eluser]sunnyd[/eluser]
Hi I hope someone can help me here...
I have been looking to set up a Category > Subcategory system using CodeIgniter (Brilliant Framework btw). I have tried almost everything I can think of... I came across this piece of code while scouring the web
Code:
function fetch_categories()
{
/* $this->db->order_by('cat_name');
$query = $this->db->get('shop_category');
if ($query->num_rows > 1)
{
return $query->result_array();
} */
$data = array();
$this->db->select('cat_id,cat_name,cat_parent_id');
// $this->db->where('status', 'active');
$this->db->orderby('cat_parent_id','asc');
$this->db->orderby('cat_name','asc');
$this->db->groupby('cat_parent_id,cat_id');
$Q = $this->db->get('shop_category');
if ($Q->num_rows() > 0){
foreach ($Q->result() as $row){
if ($row->cat_parent_id > 0){
$data[0][$row->cat_parent_id]['children'][$row->cat_id] = $row->cat_name;
}else{
$data[0][$row->cat_id]['cat_name'] = $row->cat_name;
}
}
}
$Q->free_result();
return $data;
}
Although, it looks like what I need, I cant seem to find a way of using the code to display my category and subcategory list.
Anyone have an idea of how I could use the above code?
Thanks