MySQL SELECT查询在PHP数组中
问题描述:
I have a PHP array and what I am trying to do is use that in my MySQL query to select only the ones that are in the array.
I have this:
SELECT * FROM table IN ('.implode(',', $array).')
I guess what needs to happen is I need quotes around each array item for this to work. Right now it just has one, two, three, four where it should be "one", "two", "three", "four"
How could I do that? Or is there another way to do what I am looking for?
Thanks!
我有一个PHP数组,我想要做的是在我的MySQL查询中使用它只选择那些 在数组中。 p>
我有这个: p>
SELECT * FROM table IN('.implode(',',$ 数组)。')
code> pre>
我想需要发生的事情是我需要在每个数组项周围引用它才能工作。 现在它只有一,二,三,四 strong>,它应该是“一个”,“两个”,“三个”,“四个” strong> p> \ n
我怎么能这样做? 或者有其他方法可以做我想要的吗? p>
谢谢! p>
div>
答
This would do it,
"'" . implode("','", $array) . "'"