how do i get data from a database by using an array of ids in codeigniter?

Controller:-

$toppings = $this->input->post('topping');    //Array         
$toppinglist = $this->toppingmodel->find_topping($toppings);

model:-

function find_topping($idArr = array()){         //Array  
 $query = $this->db->where_in("Topping", $idArr)->get("tablename");
     return $query->result_array();
}

Note:- $idArr = array() means

make the function have a default value of array otherwise if something else is passed you’ll get an error in your query.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top