带有php数组的MySQL SELECT语句 [英] Mysql SELECT statement with php array
本文介绍了带有php数组的MySQL SELECT语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在php中创建了一个数组,其中包含一些USER_ID.我正在使用具有名为USERS的表的mysql数据库. 现在,我只想从USERS中选择那些user_id与数组中的USER_ID相匹配的行.
I have created an array in php containing a few USER_IDs. I am using mysql database having a table named USERS. Now I want to select only those rows from USERS whose user_id is matched with USER_IDs in the array.
预先感谢
推荐答案
$ids = join(',',$user_ids);
$sql = "SELECT * FROM USERS WHERE user_id IN ($ids)";
使用WHERE子句将数组传递给查询
http://www.php.net/manual/en/function.join. php
http://www.php.net/manual/en/function.implode. php
Passing an array to a query using a WHERE clause
http://www.php.net/manual/en/function.join.php
http://www.php.net/manual/en/function.implode.php
这篇关于带有php数组的MySQL SELECT语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文