php - how can I call multiple category by ID in a model in codeigniter? -


model::::

public function selectcategory($per_page, $offset) {     $this->db->select('*');     $this->db->from('tbl_category');     $this->db->where('category_id', 23);     //$this->db->order_by("category_id", "desc");       $query = $this->db->get('', $per_page, $offset);     foreach ($query->result() $row)         $data[] = $row;      return $data; }  

this model working well. want call multiple id db table such :::

 $this->db->where('category_id', 23 && 24); 

in case showing error... "message: undefined variable: data" ... me multiple ids.

seems want items correspond either of 2 categories, need or statement:

where category_id = 23 or category_id = 24,  

using ci's active record class:

$this->db->where('category_id', 23); $this->db->or_where('category_id', 24); 

update

your error "undefined variable: data" because query not producing results $data never declared, add $data = array(); before loop:

$query = $this->db->get('', $per_page, $offset); $data = array(); foreach ($query->result() $row)     $data[] = $row;  return $data; 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -