Sukhwinder Sodhi
Sukhwinder Sodhi

Reputation: 475

fetching data separated by comma in where

Can any one tell me that how i can get name when value is separated by comma in where clause.

This is what i tried:

  $this->db->select("seller.name");
  $this->db->from("seller");
  $this->db->where("id",'29,25');
  $q = $this->db->get();
  $res = $q->row_array();
  echo $res['name'] ;

I want to print all name with id 29,25 without using another where query but mine is printing only one with id 29

Upvotes: 0

Views: 78

Answers (1)

devpro
devpro

Reputation: 16117

If you want to use two ids in where clause than you can use where_in like:

$this->db->select("name"); 
$this->db->from("seller"); 
$this->db->where_in("id",array(29,25)); 
$q = $this->db->get(); 
$res = $q->result_array(); 

Here ids use as an array array(29,25)

For printing the result use foreach loop:

foreach($res as $value){
    echo "Name: ".$value['name'] . "<br>";
}

Upvotes: 1

Related Questions