开发者

how do I query mysql table with array? [closed]

Closed. This question needs details or clarity. It is not currently acceptin开发者_高级运维g answers.

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜