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!
You'll notice the use of the $this->db->where() function, enabling you to set the WHERE clause. You can optionally pass this information directly into the update function as a string: $this->db->update('mytable', $data, "id = 4");
We can pass an array with the help of where IN clause.
Use the below query to display the query string: print_r($this->db->last_query()); To display the query result follow this: print_r($query);
$where = "name='Joe' AND status='boss' OR status='active'"; $this->db->where($where);
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With