PHP& Mysql:PHP通过列表过滤数据库中的查询 [英] PHP & Mysql : PHP filtering query from database over a list

查看:141
本文介绍了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)";

这篇关于PHP& Mysql:PHP通过列表过滤数据库中的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆