Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中处理多种类型的数组_Php_Mysql_Arrays_Codeigniter - Fatal编程技术网

在php中处理多种类型的数组

在php中处理多种类型的数组,php,mysql,arrays,codeigniter,Php,Mysql,Arrays,Codeigniter,我有多个动态文本框 <input type="text" name="Paid_Amount[]"> <input type="text" name="Charges_Type[]"> 我需要将支付金额(从获取)设置为分期付款表的支付金额 要求是:如果我在土地成本中设置了12000,那么10000应该在第一期中设置,剩余的2000将在下一期中设置 我尝试过使用foreach和do-while循环,但对多个数组感到困惑: $Charges_Type = $this->

我有多个动态文本框

<input type="text" name="Paid_Amount[]">
<input type="text" name="Charges_Type[]">
我需要将支付金额(从
获取)设置为分期付款表的支付金额

要求是:如果我在土地成本中设置了
12000
,那么
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个数组

$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);
                                }
                            }
                        }       
                    }
$merge=array\u merge($Paid\u Amount,$result);
foreach($merge as$key=>$value)
{
如果(!empty($merge[$key]))
{
foreach(结果为$in)
{
如果($in['Charges\u Type']==$key)
{
$i=0;
做
{
如果($in['分期付款金额]>=$value&&$in['Paid\u Amount']==0&&$in['Charges\u Type']==key)
{
回显“更新'tbl'u分期付款'SET'Paid'u Amount`='”、'Paid'u Date`='、'Is'u Paid`='1',其中'ID`='.['ID'.]中的$in['ID'.]和'Charges'u Type`='.$key.'';
$value=$value-$in[“分期付款金额”];
}
如果($in['分期付款金额]<$value&$in['Charges\u Type']==$key)
{
echo“UPDATE`tbl`u分期付款`SET`Paid\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
$value=$value-$in[“分期付款金额”];
}
如果($i['Paid\u Amount']!=0&&$in['Charges\u Type']==$key)
{
$value=$value+$i[“已付金额”];
echo“UPDATE`tbl\'u分期付款`SET`Paid\'u Amount`='”、`Paid\'Date`='”、`Is\'u Paid`='1'其中`ID`='”、`ID'.''中的$;
$value=0;
}   
$i++;
} 
而($value>0);
}
}
}       
}

我没有回答您的问题,但提供了另一种编写代码的方法,通过重构代码使其更易于阅读。这使得使用多个阵列循环时更容易

我注意到在你的表,分期付款表中,你有一个拼写错误,支付金额,我不确定这是你发布时的拼写错误还是SQL中的错误。但这可能导致一些问题

$merge = array_merge($Paid_Amount, $result);
foreach ($merge as $key => $value)
{
    if(empty($merge[$key]))
        continue;

    foreach($result as $in)
    {
        if($in['Charges_Type'] != $key)
            continue;

        $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);
    }
}
$merge=array\u merge($Paid\u Amount,$result);
foreach($merge as$key=>$value)
{
if(空($merge[$key]))
继续;
foreach(结果为$in)
{
如果($in['Charges\u Type']!=$key)
继续;
$i=0;
做
{
如果($in['分期付款金额]>=$value&&$in['Paid\u Amount']==0&&$in['Charges\u Type']==key)
{
回显“更新'tbl'u分期付款'SET'Paid'u Amount`='”、'Paid'u Date`='、'Is'u Paid`='1',其中'ID`='.['ID'.]中的$in['ID'.]和'Charges'u Type`='.$key.'';
$value=$value-$in[“分期付款金额”];
}
如果($in['分期付款金额]<$value&$in['Charges\u Type']==$key)
{
echo“UPDATE`tbl`u分期付款`SET`Paid\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\;
$value=$value-$in[“分期付款金额”];
}
如果($i['Paid\u Amount']!=0&&$in['Charges\u Type']==$key)
{
$value=$value+$i[“已付金额”];
echo“UPDATE`tbl\'u分期付款`SET`Paid\'u Amount`='”、`Paid\'Date`='”、`Is\'u Paid`='1'其中`ID`='”、`ID'.''中的$;
$value=0;
}   
$i++;
}而($value>0);
}
}

没有拼写错误。。你错过了第三个阵列。。我必须更新记录,其中土地成本=土地成本开发费用=开发费用我没有添加或删除任何阵列。我编辑了代码以使其更易于阅读。$result从何而来?是的,我知道,但我告诉你只是为了提供信息。我有3个数组1。金额2。费用类型(土地成本、开发费用等)3。查询数组(表中的记录)$query=$this->db->query(“从
tbl\u分期付款
WHERE
Plot\u ID
=”“$Plot\u ID.”和
已付金额
分期付款
处于活动状态
=“0”)$结果=$query->result_array();
$merge = array_merge($Paid_Amount, $result);
foreach ($merge as $key => $value)
{
    if(empty($merge[$key]))
        continue;

    foreach($result as $in)
    {
        if($in['Charges_Type'] != $key)
            continue;

        $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);
    }
}