这是我运行my sql查询的代码,我正在使用ajax,如果$contactgroup使用run the query with和condition运行查询,但现在它只是在不使用AND condition的情况下运行查询,我正在打印$contactgroup和$sql,它打印数据,但它不使用AND condition运行查询,我不知道为什么这一个不起作用,

<?php
$contactgroup=$_GET['contactgroup'];
print $contactgroup;

$sql  = "SELECT * FROM contact where isdeleted = 0 ";
print $sql;

if ($contactgroup !="" && $contactgroup !="Empty" ){

    print "contact group is null or empty";

    $contactgroup_exp = explode(',', $contactgroup);
    $sql .= " AND contactgroup in ('".implode("', '", $contactgroup_exp)."')";

}

?>

现在我的打印查询结果是
SELECT * FROM contact where isdeleted = 0

如果$contactgroup不为null或空,我想要的是这样的
SELECT * FROM contact where isdeleted = 0 AND contactgroup in ('xxxxxxx')

有人能告诉我哪里出错了吗,谢谢

最佳答案

SELECT * FROM contact where isdeleted = 0 AND contactgroup IS NOT NULL;

关于php - MySQL查询无法正常运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23969898/

10-09 08:24