arrange category and subcategory in php and Codeigniter -
here have database table , table name category store data category , subcategory in category column
i want fetch data format in ul li code have trying arrange not fetch data please me arrange code format.
you can try this
//to select categories $this ->db-> select(); $this->db->from('category'); $this->db->where('pid',0); $query = $this->db->get(); $categories = array(); $i=0; foreach ($query->result_array() $row) { //put category names $categories array $categories[$i] =$row['category']; $i++; } //to select relevant sub categories $sub_categories=array(); foreach ($categories $category) { $this ->db-> select(); $this->db->from('category'); $this->db->like('category', $category, 'after'); $query = $this->db->get(); $j=0; foreach ($query->result_array() $row) { //put sub categories names $sub_categories array $sub_categories[$category][$j] =$row['category']; $j++; } } $return_data['categories']=$categories; $return_data['sub_categories']=$sub_categories; return $return_data;
Comments
Post a Comment