how do I query mysql table with array? [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question$array contains multiple values for example $array = mathew,thomas,ethan,joseph;
I need to do a mysql query with all names and retrieve its individual values.
"WHERE name IN ('" . implode("','", array_map('mysql_real_escape_string', $array)) . "')"
By adding the quotes this way (use copy paste the quotes may be hard to see) it will let you match strings, and it will escape them as well.
If it's just numbers you can do the simpler:
"WHERE name IN (" . implode(",", $array) . ")"
$query="SELECT * FROM tablw WHERE username IN(".array_map(function($x){
return '"'.$x.'"'; // add quotes
},implode(',',$array)).")";
// now you can execute query
Don't forget to escape all data (You can do it in array_map
)
精彩评论