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

问题描述:

我有一个jQuery列表,它在php页面上返回了一个用户名列表,例如

I have a jQuery list which is returning a list of user_name on php page like

rohit,Bhalu,Ram

现在我想从数据库中筛选出不在上面列表中的用户名

Now I want to filter the user_names from the database which is not the part of above list

到目前为止,我正在尝试mysql的基本查询,例如

So far I am trying the basic query of mysql like

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

但是上述查询的问题是,这不是包含1000个user_name的较大列表的特定解决方案,因此我想对php使用一些查询过滤器

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

请建议我在这个阶段应该做什么?

Please suggest me what should I do in this stage ?

字段user_name的首次使用索引.

First use index for field user_name.

第二次使用此查询(在$ array-用户名中)

Second use this query (in $array - usernames)

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