简体   繁体   English

PHP&Mysql:PHP过滤列表中的数据库查询

[英]PHP & Mysql : PHP filtering query from database over a list

I have a jQuery list which is returning a list of user_name on php page like 我有一个jQuery列表,它在php页面上返回一个user_name列表,例如

rohit,Bhalu,Ram 罗希特(Rohit)

Now I want to filter the user_names from the database which is not the part of above list 现在我想从数据库中过滤掉user_names,这不是上面列表的一部分

So far I am trying the basic query of mysql like 到目前为止,我正在尝试像

 select * from table_name where user_name NOTIN('rohit','Bhalu','Ram');

But problem with above query is, this a not the specific solution for bigger list which contains 1000 user_name so I want to use some query filter with php 但是上述查询的问题是,这不是包含1000个user_name的较大列表的特定解决方案,因此我想对php使用一些查询过滤器

Please suggest me what should I do in this stage ? 请建议我在这个阶段应该做什么?

First use index for field user_name. 首先将索引用于字段user_name。

Second use this query (in $array - usernames) 第二次使用此查询(在$ array-用户名中)

$array = array('Rohit', 'Bhalu');
$comma_separated = implode("','", $array);
$comma_separated = "'".$comma_separated."'";
$query = "select * from table_name where user_name NOT IN($comma_separated)";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM