gpt4 book ai didi

php - 如何编写一个函数来改变日期值?

转载 作者:行者123 更新时间:2023-11-29 23:47:54 24 4
gpt4 key购买 nike

这是我用来配置日期选项的表格。

+-------+---------+-----------+
| id | date | amount |
+-------+---------+-----------+
| 1 | 5 | 200 |
| 2 | 15 | 500 |
| 3 | 25 | 1000 |
+-------+---------+-----------+

就我而言,我检查当前日期并希望将其与我的数据库日期进行比较并返回相应的金额。例如

如果当前日期是 6-15,我必须在基本金额上添加 200。

如果当前日期是 16-25,我必须在基本金额上添加 500。

如果当前日期是 26-接下来的 5,我必须在基本金额上添加 1000。

我正在使用 Codeigniter。我该怎么做呢?

public function add_fee($dt) {

$not_paid = 'Not Yet Paid';
$late_fee = $this->get_amount($dt);
$this->db->where('date', $not_paid);
$this->db->set('due', 'due'+$late_fee, FALSE);
$this->db->update('fee');
}

我在编写 `get_amount($dt); 时遇到问题

给我一​​些想法。我必须更改我的 Late_fee 表吗?或者其他什么?

最佳答案

您可以将 $from, $to 参数而不是 $dt 传递给 get_amount() 或者可以使 $from, $to var 位于 get_amount() 内,条件相同。你可以这样尝试...

function get_amount( $from, $to )
{
$this->db->select('amount');
$this->db->where('date>=', $from);
$this->db->where('date<=', $to);
$query = $this->db->get('table_name')->result();
if($query->num_rows > 0){
$row = $query->row();
return $row->amount;
}
return 0;
}

function add_fee($dt) {
$not_paid = 'Not Yet Paid';
$from = ''; $to = '';
if($dt >=6 && $dt <= 15){
$from = 6; $to = 15;
}elseif($dt >=16 && $dt <= 25){
$from = 16; $to = 25;
}elseif($dt >=26 && $dt <= 30){
$from = 26; $to = 30;
}
$late_fee = $this->get_amount($from, $to);
$this->db->where('date', $not_paid);
$this->db->set('due', 'due'+$late_fee, FALSE);
$this->db->update('fee');
}

关于php - 如何编写一个函数来改变日期值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25822591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com