gpt4 book ai didi

php - 当我使用 concat 时,Mysql 查询不起作用

转载 作者:行者123 更新时间:2023-11-29 05:20:46 30 4
gpt4 key购买 nike

我不明白为什么下面的查询没有返回任何东西。如果我更改查询,那么它将返回结果。

我现在在做什么(无输出)

$msg =  array();
$getSearch = "SELECT contact_details . * , company.company_name, users.nickname FROM contact_details LEFT JOIN users ON users.user_id = contact_details.user_id LEFT JOIN company ON company.cid = contact_details.cid WHERE";

if(!empty($ad_company)){
$getSearch .= "company.company_name LIKE '$ad_company%' ";
}

$getSearch = mysql_query($getSearch);
while($searchResult = mysql_fetch_array($getSearch)){
$msg[] = $company = $searchResult['company_name'] . "<br/>";
}
echo json_encode($msg);

更改代码(工作)

$msg =  array();
$getSearch = "SELECT contact_details . * , company.company_name, users.nickname FROM contact_details LEFT JOIN users ON users.user_id = contact_details.user_id LEFT JOIN company ON company.cid = contact_details.cid WHERE company.company_name LIKE '$ad_company%'";

//$msg[] = empty($ad_company) ? "empty company" : "not empty company"; //for checking and field has value

/*if(!empty($ad_company)){
$getSearch .= "company.company_name LIKE '$ad_company%' ";
}*/

$getSearch = mysql_query($getSearch);

while($searchResult = mysql_fetch_array($getSearch)){
$msg[] = $company = $searchResult['company_name'] . "<br/>";
}
echo json_encode($msg);

最佳答案

可能是因为您在 WHERE 和 company 之间没有空格?

关于php - 当我使用 concat 时,Mysql 查询不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26140159/

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