arrange category and subcategory in php and Codeigniter -


here have database table , table name category store data category , subcategory in category column 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. i want fetch data format in ul li  code have trying arrange format not fetch data format 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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -