If you are trying to select multiple ID values, use IN conditional:
SELECT * FROM mytable WHERE id IN ($v1, $v2, $v3)
EDIT: Asked for a flexible way to add values:
Assuming that this query is set by a function and this function will receive all ID values that should be in where clause. Something like:
<?php
$example_ids = array(1, 5, 7, 15, 22);
wherein($example_ids)
function wherein($ids){
// Select part
$query = "SELECT * FROM mytable ";
// Where statement
$where = " WHERE id IN (";
// For loop to use each value sent
// as a value in IN (...
for ($i=0; $i < count($ids); $i++) {
// Eg: $i = 0
// $ids[$i] = 1
//
// So:
// WHERE id IN (1
$where .= $ids[$i];
// If its not the last value then
// add a comma for SQL syntax
if ($i < count($ids) - 1)
/// Where id IN (1,
$where .= ",";
}
// At the end of the loop, $where must be
// something like:
// WHERE id IN (1,5,7,15,22
//
// Once again, for SQL syntax, the close )
$where .= ")";
// Finaly, the last step, putting all together:
// SELECT * FROM mytable WHERE id IN (1,5,7,15,22)
$query .= $where;
}
idis equal to more than one value? What's in$v2or$v3? Are you adding SQL string conditions in those variables? Or actual data?id=x and ydoesn't make much sense. Isidsupposd to be equal to both of those value, or shouldidbe equal to the logical AND of the two values?