views:

243

answers:

2

Hey!

I am using the following code to select from a MySQL database with a Code Igniter webapp:

$query = $this->db->get_where('mytable',array('id'=>10));

This works great! But I want to write the following MySQL statement using the CI library?

SELECT * FROM `mytable` WHERE `id`='10' OR `field`='value'

Any ideas? Thanks!

+2  A: 
$where = "name='Joe' AND status='boss' OR status='active'";

$this->db->where($where);
Dylan
A: 

You can use or_where() for that - example from the CI docs:

$this->db->where('name !=', $name);

$this->db->or_where('id >', $id); 

// Produces: WHERE name != 'Joe' OR id > 50
Rookwood
according to the documentation or_where is deprecated. http://codeigniter.com/user_guide/database/active_record.html
Matthew J Morrison
I believe you might have misread that. It seems to me to be saying that the old method, orwhere(), has been deprecated in favor of the new method or_where().
Rookwood