2011-10-04 52 views
1
if ($this->input->get('beds')) 
    $where['Bedrooms'] = $this->input->get('beds'); 

if ($this->input->get('baths')) 
    $where['Bathrooms'] = $this->input->get('baths'); 

$min_price = ($this->input->get('min_price')) 
    ? $this->input->get('min_price') 
    : '0'; 

$max_price = ($this->input->get('max_price')) 
    ? $this->input->get('max_price') 
    : '10000000'; 

$q = $this->db->select("*") 
    ->where('ListingPrice <=', $max_price) 
    ->where('ListingPrice >=', $min_price) 
    ->limit(10) 
    ->get(); 

是嗎?你可以相信所有的價值都在那裏。CodeIgniter數據庫查詢有錯誤但我看不到它

的錯誤是:

您的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的「WHERE ListingPrice < =‘100000’AND ListingPrice> =‘0’LIMIT 10」在第2行

+1

那麼,你得到的是什麼錯誤?什麼不起作用? –

+3

我沒有使用CodeIgniter,但似乎沒有查詢的FROM元素 – Clive

+0

您的SQL語法錯誤;檢查與您的MySQL服務器版本相對應的手冊,以在'第二行'WHERE'ListingPrice' <='100000'AND'ListingPrice'> ='0'LIMIT 10'處使用正確的語法 –

回答

3

我不使用笨,但似乎沒有成爲一個FROM元素查詢

3

你沒有指定正確的語法手冊你正在查詢的表格。嘗試在get方法內設置表名,或者在查詢中使用from()方法。

->get('table_name'); 

此外,如果你只是選擇一切(「*」),您可以從您的查詢離開了select()因爲它會默認選擇的一切。

2

看起來像你的控制器內混合MODEL也嘗試使用Profiler來得到你的「錯誤」 => $這個 - >輸出 - > enable_profiler(TRUE)更多細節;

否則你缺少了FROM:
$q = $this->db->select('*')->from('TABLE')....

相關問題