I Have an array of different ids, I want to iterate this array and use these ids to be compared with a single field in DB Table
Example
classid{
0=>1,
1=>2
}
and I have table as
id name
1 myname
2 ur name
3 everyonename
Now how can i retrieve the values for both id=1 and id = 2 in just a Select query?
The query you want is:
To create this from PHP, you would use something like
You should be ultra careful to prevent SQL injections if the values in
$classidare coming from an external source! Normally this is achieved with prepared statements and bound parameters, but in this case (where you want to useIN) this is not possible AFAIK.Therefore you should sanitize the values yourself, using something like
Read more about protecting yourself from SQL injection.