我在代码点火器工作。我做了一个函数,通过连接另外 4 个表(包括价格表)来获取所有产品。我需要产品的最低价格。怎么做呢???我的代码是:-
function fetch_all_products()
{
$query = $this->db->select('*')
->from('products')
->join('reviews','products.ID=reviews.product_id','left')
->join('product_price','products.ID=product_price.product_id','left')
->join('product_news','products.ID=product_news.product_id','left')
->join('websites','websites.ID=product_price.website_id','left')
->group_by('products.Name')->order_by('product_price.price','asc')->where('status',1);
$query = $this->db->get();
return $query->result();
}
我得到很多产品,每个产品都有很多价格,现在我必须以最低的价格展示每个产品......
您可以使用
CI 函数select_min
获得最小值
$this->db->select_min('price');
或者订购:
$this->db->order_by("price", "asc");
$this->db->limit(1);
从中,您应该得到一组行,其中包含第一个位置价格最低的产品。
你为什么不直接得到第一排的价格?