2013-08-27 61 views
-1

我想從數據庫中使用Codeigniter獲得列的最小值,但不是零。獲取最小值但不爲零(0)

這是我正在使用的當前代碼,但它給了我0因爲列也有0值。

$this->db->select_min('saleprice'); 
     $this->db->join('category_products', 'category_products.product_id=products.id', 'right'); 
     $this->db->where('category_products.category_id', $cat_id); 
     $this->db->where('products.enabled',1); 
     return $this->db->get('products')->row_array(); 

請讓我知道如何獲得最低值,但不爲0

回答

3

嘗試添加where條件這樣

$this->db->where('saleprice >','0'); 

然後將查詢將成爲

$this->db->select_min('saleprice'); 
$this->db->join('category_products', 'category_products.product_id=products.id', 'right'); 
$this->db->where('category_products.category_id', $cat_id); 
$this->db->where('products.enabled',1); 
$this->db->where('saleprice >','0'); //Add this 

你也可以使用!=,如

$this->db->where('saleprice !=','0');  
+1

是的,它的工作。感謝名單 –