0

Hi,

I have a MySQL database and an array with ID's. For example:
$q = array(4,7,9,34,12,3,...etc);
The ID count in array can be over 100. What's the best way to select only those rows matching those ID's in array? The usual
SELECT *
FROM table
WHERE ID = '$q[0]'
OR ID = '$q[1]'
OR ID = '$q[2]'
... etc
seems a bit wrong in this case. Does it decreases performance greatly if there are over 100 OR's in the statement? Maybe there is a better solution?

Thanks

Edited by Buppy: n/a

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by urtrivedi
0
$list=implode(",",$q);

$query=" SELECT * 
FROM table 
WHERE ID in ($list)";

Edited by urtrivedi: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.