Home  >  Article  >  Backend Development  >  请问 php中数组做为mysql查询条件 where xx in array,怎么办

请问 php中数组做为mysql查询条件 where xx in array,怎么办

WBOY
WBOYOriginal
2016-06-13 12:22:471816browse

请教 php中数组做为mysql查询条件 where xx in array,怎么处理
原先想着把数组 $customerid 拆分出来,判断长度给不同的变量,变量多少还要再判断,然后写 下边的mysql查询,有些麻烦,请教有没有好的方法,谢了!

---------------------------------------------
$customerid:

array (size=2)
  0 => string '5' (length=1)
  1 => string '14' (length=2)
----------------------------------------------

$customer->where("id in ".$customerid)->count();     //是这个意思,当然,数组直接放这里是不对的
------解决思路----------------------
第一个问题,如果是查单一id,直接id = xx就可以,没必要用in
如果想查多个id,把数组用implode函数组合成id in (1, 2, 3) 这种格式的字符串
最后的问题,如果你的需求是输出用户列表,同时输出每个人前10条收藏,就要考虑缓存了

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn