gpt4 book ai didi

php - 如何在查询运行之前删除查询中的字符

转载 作者:行者123 更新时间:2023-11-29 12:56:27 25 4
gpt4 key购买 nike

这是我的查询

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



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



$language_exp = explode(',', $language);
$sql .= " INNER JOIN contactlanguage ON contact.id = contactlanguage.contactid
INNER JOIN language ON contactlanguage.languageid = language.id where isdeleted = 0 AND language.language in ('".implode("', '", $language_exp)."') ";

}

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



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

}

如果我运行该函数,查询结果如下

SELECT * FROM contact where isdeleted = 0 INNER JOIN contactlanguage ON contact.id = contactlanguage.contactid INNER JOIN language ON contactlanguage.languageid = language.id where isdeleted = 0 AND language.language in ('English', 'Arabic', '')

这里isdeleted = 0是两次谁能告诉我如何在内部条件之前以及查询运行之前删除 isdeleted = 0 ,谢谢

最佳答案

简单的解决方案是:

$sql = "SELECT * FROM contact";
if ($language !="" && $language !="Empty" ){
//...
$sql .= " INNER JOIN .....";
}
else {
$sql .= " where isdeleted = 0";
}

// run query...
$query = mysql_query($sql);

关于php - 如何在查询运行之前删除查询中的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23989821/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com