2013-11-26 73 views
0

我在計算如何解決此查詢時遇到問題。包含WHERE,AND或OR子句的SQL語句的問題codeigniter

這裏是我笨代碼

return $this->db 
     ->select('vehVin, vehMake, vehModel, seller, dealership, buyer, logistics.warehouseName, transportDate, car_tracking.keys, car_tracking.window') 
     ->where('transportDate <', $yesterday) 
     ->where('(car_tracking.keys', "'0'", FALSE) 
     ->or_where("car_tracking.stickers = '0')", NULL, FALSE) 
     ->join('logistics', 'logistics.stockid = vehicles.stockid') 
     ->join('car_tracking', 'car_tracking.stockid = logistics.stockid') 
     ->get('vehicles') 
     ->result(); 

這是我得到

Unknown column 'car_tracking.stickers' in 'where clause' 

`SELECT `vehVin`, `vehMake`, `vehModel`, `seller`, `dealership`, `buyer`, `logistics`.`warehouseName`, `transportDate`, `car_tracking`.`keys`, `car_tracking`.`window` 
FROM (`vehicles`) 
JOIN `logistics` ON `logistics`.`stockid` = `vehicles`.`stockid` 
JOIN `car_tracking` ON `car_tracking`.`stockid` = `logistics`.`stockid` 
WHERE `transportDate` < '2013-11-25' 
AND (car_tracking.keys = '0' OR car_tracking.stickers = '0')` 

由於提前對您有所幫助的錯誤!

回答

1

確保car_tracking.stickers存在。 我也會考慮把sql查詢原始的。因爲codeigniter的查詢生成器有很多問題。當它們一起使用時,它不能處理大多數查詢條件。