Is there a shortcut for writing the following mySQL query? I am looking for a shorthand to compress
SELECT * FROM `listings` where `bedroom` = 1 OR `bedroom` = 2
because I want to make it easier to dynamically build a mySQL query in PHP. Something like WHERE bedroom = 1, 2
because the numbers that I am getting from PHP is in an array bedroom[1] = 1, bedroom[2] = 1
.
SELECT * FROM `listings` where `bedroom` = 1 OR `bedroom` = 2;
And because I am using Codeigniter, some shortcut for this in Active Record will be great too!
I don't understand very well what you're asking; do you need a shorter query?
If so, try this:
SELECT * FROM listings WHERE bedroom IN (1,2)
Use the IN
syntax:
SELECT * FROM `listings` where `bedroom` IN (1,2);
You can write:
SELECT * FROM `listings` where `bedroom` in (1,2);
With ActiveRecord:
$this->db->from("listings")->where_in("bedroom",bedroom)