【问题标题】:Best way to filter the value in Mysql-PHP在 Mysql-PHP 中过滤值的最佳方法
【发布时间】:2012-11-05 17:40:38
【问题描述】:

我的 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 表中过滤数组数据的最佳方法

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    parenthesis包装变量

    NOT IN ('$list')
    

    【讨论】:

    • 第一次过滤工作正常,第二次再次显示所有数据
    【解决方案2】:

    请更改下面的 sql ,因为找不到变量的值并且在 需要声明 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 .") ";        
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 1970-01-01
      • 2013-07-21
      • 2014-03-03
      • 2021-02-05
      • 1970-01-01
      • 2020-10-24
      相关资源
      最近更新 更多