我正在尝试使 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 之后。