I need to select multiple rows in db (using MYSQL). I create the following query by iterating over array of ids:
$ids = array(1,2);
$idq = array();
$q = "SELECT * FROM table_name WHERE ";
foreach($ids as $id)
{
$idq[] = "`ID` = '" . $id . "'";
}
$q .= implode(" AND ", $idq);
SELECT * FROM table_name WHERE `ID` = '1' AND `ID` = '2'
For some reason it doesn't seem to work:
The above won't work. Is there a better way?
When I do:
`SELECT * FROM table_name WHERE `ID` = '1'`
It works fine but when I add the AND ID = '2' it won't work at all.