代码点火器或AND多个Where子句

时间:2011-06-20 10:57:30

标签: php codeigniter

使用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 ...包含在搜索中

有人可以帮帮我吗?

谢谢堆

1 个答案:

答案 0 :(得分: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));