我想這一點:多加入與在那裏,喜歡和or_like 3笨的活動記錄
$location = 'a';
$this->db->select('l.id, d.guests, l.city, l.country');
$this->db->from('offers as o');
$this->db->join('location as l', 'l.id = o.id', 'left');
$this->db->join('desc as d', 'd.offer_id = o.id', 'left');
$this->db->where('d.guests', $guests);
$this->db->where('o.completed', 1);
$this->db->where('l.country LIKE', $location.'%');
$this->db->or_where('l.city LIKE', $location.'%');
$this->db->limit(5);
而且我有3位客人,並與國家阿爾巴尼亞(每桌1行吧)的報價。但是,如果$guests = 2;
我有這1行的結果。同樣,如果我使用like
和or_like
而不是where
和or_where
。如果我評論這一行:
$this->db->or_where('l.city LIKE', $location.'%');
一切工作正常,我如果$guests != 3
和1行的結果,如果$guests = 3
沒有結果。
生成的查詢與$this-db->last_query()
是:
SELECT 'l'.'id', 'd'.'guests', 'l'.'city', 'l'.'country' FROM 'offers' as 'o' LEFT JOIN 'location' as 'l' ON 'l'.'id' = 'o'.'id' LEFT JOIN 'desc' as 'd' ON 'd'.'id' = 'o'.'id' WHERE 'd'.'guests' = 3 AND 'o'.'completed' = 1 AND 'l'.'country' LIKE 'a%' OR 'l'.'city' LIKE 'a%' LIMIT 5
我怎樣才能讓這個查詢? 選擇已完成的值= 1,客人= $guests
以及城市或國家/地區$location
。
'您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以在'%或'l'.city'附近使用正確的語法。LIKE a%)LIMIT 5'' – gdfgdfg
我已更新我的答案 – parth