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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

android - How to create dynamically Fragment pager adapter -

1111. appearing after print sequence - php -