如何在一列中获取所有数据?

时间:2019-05-21 03:31:22

标签: codeigniter

this is the actual I want to expect我想将所有费用汇总到一栏中,我有5笔费用,但仅追加了一笔费用

                    foreach ($client_class->getLoanFeesInfoById($li_id) as $row_d){ 
                            $fee_id = $row_d->fee_id;

                                 foreach ($fees_class->getInfoByFeeId($fee_id) as $row_e) 
                                    {
                                         $fee_name = $row_e->fee_name;      
                                         $default_amount = $row_e->manual_default_amount;

                                         $disbursement_amount = $loan_amount - $default_amount;
                                    }
                            }


                        echo "<tr>

                                <td>".number_format($default_amount)."-".$fee_name."</td>
                                <td>".$deposit_code."</td>
                                <td>P".number_format($disbursement_amount)."</td>

                            </tr>";

1 个答案:

答案 0 :(得分:0)

当您回显<td>".number_format($default_amount)."-".$fee_name."</td>时,您只会得到在foreach中获得的最后一个值。因此,作为解决方案,您可以在内部foreach中使用变量来存储所有费用。

$fee = '';
foreach ($fees_class->getInfoByFeeId($fee_id) as $row_e) 
{
    $fee_name = $row_e->fee_name;      
    $default_amount = $row_e->manual_default_amount;
    $disbursement_amount = $loan_amount - $default_amount;
    $fee .= number_format($default_amount)."-".$fee_name."<br/>";
}

然后您可以回显为 <td>".$fee."</td>