簡體   English   中英

MySQL查詢無法正常運行

[英]MySQL query is not running properly

這是我運行mysql查詢的代碼,如果$contactgroup is not null or empty用AND運行查詢,則我將使用ajax獲取$contactgroup ,但現在它只運行沒有和條件的查詢,我將打印$ contactgroup和$ sql它打印數據,但不運行帶有和條件的查詢,我不知道為什么這將不起作用,

<?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;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM