CodeIgniter Forums
$this->db->where - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: $this->db->where (/showthread.php?tid=68101)



$this->db->where - Knutsford - 05-25-2017

How do I do a $this->db->where for a field where I want it to set to  a or b or c? Do I need three seperate where staements for the same field?

Thanks


RE: $this->db->where - rtenny - 05-25-2017

That depend on the type of the condition.
is this either: WHERE id=a OR id=b OR id=c
or: where id=a AND id=b AND id=c
or: where id IN (a,b,c)

Have a look at the tutorial:
https://www.codeigniter.com/userguide2/database/active_record.html#select
look at or_where, where_in, etc depending on what you try to do


RE: $this->db->where - Knutsford - 05-25-2017

(05-25-2017, 08:24 AM)rtenny Wrote: That depend on the type of the condition.
is this either: WHERE id=a OR id=b OR id=c
or: where id=a AND id=b AND id=c
or: where id IN (a,b,c)

Have a look at the tutorial:
https://www.codeigniter.com/userguide2/database/active_record.html#select
look at or_where, where_in, etc depending on what you try to do

WHERE id=a OR id=b OR id=c is what I meant


Thanks


RE: $this->db->where - rtenny - 05-25-2017

(05-25-2017, 08:33 AM)Knutsford Wrote: WHERE id=a OR id=b OR id=c is what I meant


Thanks


the I would use this

Code:
$names = array('a', 'b', 'c');
$this->db->where_in('username', $names);



RE: $this->db->where - Knutsford - 05-25-2017

$this->db->where_in worked - thanks