Codeigniter JOIN dont back db result -
codeigniter dont database result. database table "category" , "sub category"
db shema:
categor ----------------------------- id name ---------------------------- 1 fishing 2 hunting 3 test category sub_category ----------------------------- id cat_id name ---------------------------- 1 1 fishing rod 2 2 hunting ammunition 3 3 test sub category
i want list sub category category. when some1 click on fishing category want show sub category fishing. code this:
controller: public function get_sub_category($id = 0) { $this->load->model('front_m'); $data['sub_cat'] = $this->front_m->show_sub_cat($id); $this->template->set_theme('zend')->set_layout('front.html') ->build('sub_category',$data); } model: public function show_sub_cat($id=0) { $this->query = $this->db->select('*'); $this->query = $this->db->from('category'); $this->query = $this->db->where('id='.$id'); $this->query = $this->db->join('sub_category', 'sub_category.cat_id=category.id'); $this->query = $this->db->query('select * category'); $this->query = $this->db->get(); if ($this->query->num_rows() > 0) { $this->query->result(); } homecoming $this->query ; }
what wron time have db error or blanko page.
based on question sounds on thinking it, i'm bit confused well. i'm hearing is: how can sub categories based on clicking on main category id? if that's case making way more complicated needs be.
model
public function show_sub_cat($catid=null) { $result = $this->db->get_where('sub_category',array('cat_id'=>$catid)); if ($result->num_rows()>0) { homecoming $result->result(); } }
codeigniter
No comments:
Post a Comment