Code Igniter OR AND 多个Where 子句[重复]

问题描述 投票:0回答:1

使用 CodeIgniter,我想在Where子句中使用 OR 进行多重搜索..像这样:

$sql = "select employee.first_name, employee.last_name, employee.phone_number, job.title,
FROM employee, job
WHERE employee.jobID = job.jobID
AND employee.deleted = 0
AND (employee.first_name = $searchPara OR employee.last_name= $searchPara)
ORDER BY employee.last_name";
return $this->db->query($sql, $searchPara);

上面的查询给出了错误消息,而且我也不知道如何在同一个 SQL 语句中包含 job.title = $searchPara... 的搜索

有人可以帮我吗?

谢谢大家

php codeigniter
1个回答
2
投票

由于

job.title

后面的逗号而导致 SQL 错误
$sql = "select employee.first_name, employee.last_name, employee.phone_number, job.title
    FROM employee, job
    WHERE employee.jobID = job.jobID
    AND employee.deleted = 0
    AND (employee.first_name = ? OR employee.last_name = ?)
    ORDER BY employee.last_name";
return $this->db->query($sql, array($searchPara, $searchPara));
© www.soinside.com 2019 - 2024. All rights reserved.