get value from database based on array in codeigniter

Posted by Developer on Stack Overflow See other posts from Stack Overflow or by Developer
Published on 2012-12-15T10:49:24Z Indexed on 2012/12/15 11:03 UTC
Read the original article Hit count: 130

Filed under:
|
|
|

I have an array

$user = array([0]=>1 [1]=>2 [2]=>3)

which contains id's of certain users. I need to get the countries of these users from database.

foreach($userid as $user){
    $this->db->select('country');
    $this->db->where('user_id',$user);
    $this->db->from('company');
    $usercountry = $this->db->get();
    $count = $usercountry->row();
    $country = $count->country;
    }

Suppose user1 has country ES, user2 has IN, user3 has US, user4 has UK. then if array contains 1,2,3. Then i need to get the countries ES,IN,US.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about arrays