-1

我想从数据库中获取最小值但不是零列Codeigniter

这是我正在使用的当前代码,但它给了我 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

4

1 回答 1

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');     
于 2013-08-27T07:08:13.010 回答