I have a table of users with the following data:
id first_name
10 user one
21 user two
39 user 3
So I want to fetch all users with specific ids, like when I pass id of 10 and 21 I want to retrieve first 2 users.
So in Codeigniter I have a functions getUsersByIds in my model like:
class UsersModel extends CI_Model{
public function getUsersByIds($ids){
$data = [];
foreach($ids as item){
$this->db->where('user_id',(int)$item);
}
$rs = $this->db->get('users');
return $rs->result_array();
}
}
Now whenever I try calling the above model in my controller via:
$this->load->model('UsersModel');
var_dump($this->UsersModel->getUsersByIds([10,21])) //this is null
The above var_dump is null. I suspect the issue occurs on the foreach loop. Is there a way I can do where and where in Codeigniter with dynamic data like the above?
$ids as itemshould be$ids as $item, or was that just a code pasting error?