codeigniter 获取最低列值高于最小阈值的数据库表行

jtw3ybtb  于 7个月前  发布在  其他
关注(0)|答案(3)|浏览(66)

我在codeigniter电子商务网站工作。我有一个下表

shipping table

product_weight (in kgs)  shipping_charge
1.000                    60
1.500                    90
2.000                    120
2.500                    150
3.000                    180
3.500                    210
4.000                    240

字符串
我想找到运费的产品添加到购物车.但我没有计算它.如果产品重量是2.800然后我应该得到shipping_charge值180.我不知道怎么做.下面是我的代码

function get_shipping_charge(){
    $this->db->select('shipping_charge');
    $this->db->from('shipping_table');
    $this->db->where('product_weight >=', $product_weight);
    $this->db->limit('1');
    $query = $this->db->get();
    return $query->result();
}

wbgh16ku

wbgh16ku1#

function get_shipping_charge(){
$this->db->select('shipping_charge');
$this->db->from('shipping_table');
$this->db->where('product_weight >=', $product_weight);
$this->db->order_by("product_weight","ASC");
$this->db->limit('1');
$query = $this->db->get();
return $query->result();
}

字符串

qlfbtfca

qlfbtfca2#

试试这个:

function get_shipping_charge() {
    $this->db->select('MIN(shipping_charge) AS shipping_charge');
    $this->db->from('shipping_table');
    $this->db->where('product_weight >=', $product_weight);
    $query = $this->db->get();
    return $query->result();
}

字符串

9udxz4iz

9udxz4iz3#

这对你有用吗?

function get_shipping_charge() {
    $this->db->select('IFNULL(MAX(shipping_charge), (SELECT MIN(shipping_charge) FROM shipping_table))');
    $this->db->from('shipping_table');
    $this->db->where('product_weight <=', $product_weight);
    $query = $this->db->get();
    return $query->result();
}

字符串

备注

  • 更新查询以处理小于1.000的权重值。*

相关问题