我在以下函数的sql查询结果中有两个放两个条件:
目前使用以下内容:
alist[k] = leftHalf[j]
答案 0 :(得分:0)
您可以使用not
运算符添加这些条件:
SELECT *
FROM projects
WHERE a_name like '%$term%' AND
NOT (a_name = 'xxxx' and a_name = b_name)
答案 1 :(得分:0)
问题部分在查询中为$term
,因此请使用$term
替换:term
尝试更新代码:
public function search_project_name($term){
$params = array(
':term'=>$term);
$sql = "SELECT * FROM projects WHERE project_name like '%:term%'ORDER BY projects.create_date DESC $limit";
$stmt = parent::query($sql, $params);
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) :
$result[] = $row;
endwhile;
return $result;
}
您在查询中使用的$limit
还有一个缺失参数,但未传递给函数?
将$limit
作为第二个参数默认设置为10行:
public function search_project_name($term, $limit = 10){
$params = array(
':term'=>$term);
$sql = "SELECT * FROM projects WHERE project_name like '%:term%'ORDER BY projects.create_date DESC $limit";
$stmt = parent::query($sql, $params);
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) :
$result[] = $row;
endwhile;
return $result;
}