gpt4 book ai didi

php - 您的 SQL 语法有误。 MySQL Selectgiving 错误与 LIKE 和

转载 作者:行者123 更新时间:2023-11-29 03:56:54 24 4
gpt4 key购买 nike

我正在尝试使 MySQL 选择用于 mysql_query 函数,但我不断收到此错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LEFT JOIN Orgs ON Jobs.CustOrgID = Orgs.ID 
LEFT JOIN Persons ON Jobs.CustPer' at line 11

我已经尝试了所有方法并到处搜索,但似乎没有任何效果。感谢所有帮助。

 $Qry = "SELECT 

Jobs.ID,
'Jobs.Status',
Jobs.JobNum,
'Orgs.Nme',
'Persons.FirstNme',
'Persons.LastNme',
'JobTypes.JobType',
'Jobs.Dsc',
'Jobs.Notes'
FROM Jobs ";

if($column !== null && $text !== null) {
$Qry .= "WHERE " . $column . " LIKE '%" . $text . "%' ";
}

$Qry .= "LEFT JOIN Orgs ON Jobs.CustOrgID = Orgs.ID
LEFT JOIN Persons ON Jobs.CustPersonID = Persons.ID
LEFT JOIN JobTypes ON Jobs.JobTypeID = JobTypes.ID
ORDER BY JobNum";

解决方案:

     SELECT ...
FROM ...
LEFT JOIN ...
LEFT JOIN ...
WHERE ...
ORDER BY ...

我的WHERE放错了,应该在两个LEFT JOINS之后。

最佳答案

您将 WHERE 插入错误的位置。它必须在连接之后出现:

SELECT ...
FROM ...
LEFT JOIN ...
LEFT JOIN ...
WHERE ...
ORDER BY ...

关于php - 您的 SQL 语法有误。 MySQL Selectgiving 错误与 LIKE 和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753929/

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