[英]CodeIgniter Active Record unknown column in where clause
這是我的活動記錄查詢! 它一直給我錯誤在where子句中的未知列:
public function getItemSale($start, $end = 9,$userid,$loc_id,$item)
{
$sql = "SELECT Name, sum(Qty) as total, sum(Price) as sale from itransfile where
SESSIONID = GETSESSIONID(?) && PayMode IN('CASH','Cheque')" ;
if(is_numeric($loc_id))
$sql .= " && location_id = " .$loc_id ;
else
$sql .= " && location_id IN(SELECT location_id FROM client_locations where client_id = " .$userid. ")";
if($item != 'All')
$sql .= " && Name = `{$item}`";
$sql .= " group by Name order by sale desc LIMIT ? OFFSET ?;";
$query = $this->db->query($sql, array(date("Y-m-d"),$end,(int)$start));
return $query->result_array();
}
刪除backticks
並使用AND
代替&&
$sql = "SELECT Name, sum(Qty) as total, sum(Price) as sale from itransfile where
SESSIONID = GETSESSIONID(?) AND PayMode IN('CASH','Cheque')";
if (is_numeric($loc_id))
$sql .= " AND location_id = " . $loc_id;
else
$sql .= " AND location_id IN(SELECT location_id FROM client_locations where client_id = " . $userid . ")";
if ($item != 'All')
$sql .= " AND Name = '{$item}'";
$sql .= " group by Name order by sale desc LIMIT ? OFFSET ?;";
$query = $this->db->query($sql, array(date("Y-m-d"), $end, (int) $start));
return $query->result_array();
用單引號替換反 引號 。 在MySql中,反引號表示標識符是列名:
$sql .= " && Name = '{$item}'";
替換下面的行
if($item != 'All')
$sql .= " && Name = `{$item}`";
同
if($item != 'All')
$sql .= " && Name = '{$item}'";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.