【发布时间】:2016-04-11 07:39:42
【问题描述】:
我有多个动态文本框。
<input type="text" name="Paid_Amount[]">
<input type="text" name="Charges_Type[]">
每个文本框值在数据库中都有多行(分期付款)。
已付金额应按分期数分摊。
例如我有开发费用 = 50,000
如果开发收费,然后分期付款
我需要将支付金额(从<form>获取)设置为分期付款表的支付金额
要求是:如果我在土地成本中设置12,000,那么10000应该在第一期设置,剩余的2000将在下一期设置
我尝试过使用 foreach 和 do while 循环,但对多个数组感到困惑:
$Charges_Type = $this->input->post('Charges_Type'); // array
$Paid_Amount = $this->input->post('Paid_Amount'); // array
$result = array of rows from installment table
如何处理这些3 arrays:
$merge = array_merge($Paid_Amount, $result);
foreach ($merge as $key => $value)
{
if(!empty($merge[$key]))
{
foreach($result as $in)
{
if($in['Charges_Type'] == $key)
{
$i = 0;
do
{
if($in['Installment_Amount'] >= $value && $in['Paid_Amount'] == 0 && $in['Charges_Type'] == $key)
{
echo "UPDATE `tbl_installment` SET `Paid_Amount` = '".$value."', `Paid_Date` = '".$Paid_Date."', `Is_Paid` = '1' WHERE `ID` = '".$in['ID']." AND `Charges_Type` = '".$key."''";
$value = $value - $in['Installment_Amount'];
}
if($in['Installment_Amount'] < $value && $in['Charges_Type'] == $key)
{
echo "UPDATE `tbl_installment` SET `Paid_Amount` = '".$in['Installment_Amount']."', `Paid_Date` = '".$Paid_Date."', `Is_Paid` = '1' WHERE `ID` = '".$in['ID']." AND `Charges_Type` = '".$key."''";
$value = $value - $in['Installment_Amount'];
}
if($i['Paid_Amount'] != 0 && $in['Charges_Type'] == $key)
{
$value = $value + $i['Paid_Amount'];
echo "UPDATE `tbl_installment` SET `Paid_Amount` = '".$value."', `Paid_Date` = '".$Paid_Date."', `Is_Paid` = '1' WHERE `ID` = '".$in['ID']." '";
$value = 0;
}
$i++;
}
while ($value > 0);
}
}
}
}
【问题讨论】:
标签: php mysql arrays codeigniter