0

我的 PHP 和 mysql 代码中有一个选择框。

<select id="addressbook_user" name ="addressbook_user">
<option value="hi">hi</option>
<option value="hello">hello</option>
<option value="newa">newa</option>

<select>

我将选定的值存储在 jQuery 列表中,并将该列表传递给 php 代码以过滤除列表项之外的其他选项。

$list = $_GET['list'];

print $list;
print_r($list);
$query = "SELECT *  from demo_addressbook WHERE user_created_id IN(SELECT id FROM demo_user WHERE user_name = '$get_user_name') AND type = 1 AND guest_name NOT IN '$list' ";                               
$sresult    = mysql_query($query) or die (mysql_error());

并根据结果,我试图创建没有列表选定值的最新选择框。

但不幸的是,我的上述查询不起作用

hiYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'hi' at line 1 is the error .

请建议我从 mysql 表中过滤数组数据的最佳方法

4

2 回答 2

0

parenthesis

NOT IN ('$list')
于 2012-11-05T09:30:03.247 回答
0

请更改下面的 sql ,因为找不到变量的值并且需要 In 语句 lile " columnName in('','')":

$query = "SELECT *  from demo_addressbook WHERE
 user_created_id IN(SELECT id FROM demo_user 
 WHERE user_name = '" . $get_user_name . "')
 AND (type = 1) AND guest_name NOT IN(". $list .") ";        
于 2012-11-05T09:35:58.363 回答