第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從來自 api 的表列中獲取總金額的總和

從來自 api 的表列中獲取總金額的總和

PHP
哆啦的時(shí)光機(jī) 2023-07-08 21:42:35
我有一個(gè)具有唯一編號(hào)的 api,該編號(hào)不同,因此當(dāng)我使用該唯一編號(hào)調(diào)用 api 時(shí),我會(huì)返回?cái)?shù)據(jù),并在表中顯示數(shù)據(jù)。該表有一個(gè)列名稱“amount”。由于其動(dòng)態(tài)數(shù)據(jù)來自 API,我只是困惑如何在表格的最底部顯示總量。我正在使用 Laravel。我的代碼示例<table class="table table-one">       <thead class="table-success">            <tr>                <th scope="col">Inst. No.</th>                <th scope="col">PR No.</th>                <th scope="col">PR Date</th>                 <th scope="col">Prem. Amt.</th>            </tr>        </thead><!-- ends: thead -->        <tbody>         @foreach ($results['polinfo'] as $data)           @foreach ($data['poldata'] as $res)            <tr>                <th scope="row">{{$res['INSTALNO']}}</th>                <td>{{$res['PR_NO']}}</td>                <td>{{$res['PR_DATE']}}</td>                <td>{{$res['AMOUNT']}}</td>            </tr>       @endforeach         @endforeach        </tbody><!-- ends: tbody -->    </table>我必須計(jì)算所有 {{$res['AMOUNT']}} 并必須將其顯示為總金額。
查看完整描述

1 回答

?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊

如果您只需要后面的值,foreach您可以使用一個(gè)單獨(dú)的變量來添加金額:


@php($amount = 0)


@foreach ($results['polinfo'] as $data) 

    @foreach ($data['poldata'] as $res)

        <tr>

            <th scope="row">{{$res['INSTALNO']}}</th>

            <td>{{$res['PR_NO']}}</td>

            <td>{{$res['PR_DATE']}}</td>

            <td>{{$res['AMOUNT']}}</td>

        </tr>

        

        @php($amount += (int) $res['AMOUNT'])

    @endforeach

@endforeach


Amount: {{ $amount }}


查看完整回答
反對(duì) 回復(fù) 2023-07-08
  • 1 回答
  • 0 關(guān)注
  • 140 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)