Laravel刀片模板中的嵌套循环

时间:2019-03-22 11:08:38

标签: laravel

这是我的控制人

当我运行此控制器代码时,由于所有数据都是正确的,因此获得了以下屏幕截图中的结果。

$query = DB::table('intis_auctions_lots')
        ->select('bidincrement','intis_lot_id','lot','product_name','maxbid','enddate')
        ->where([['community_name','=',$CommunityNo],['SellerId','=',$SellerId],['active','=','Y'],['startdate','<',$now],['enddate','>',$now]])
        ->orderBy('intis_lot_id')
        ->get();

foreach($query as $querys) {
    $qintis_lot_id = $querys->intis_lot_id;
    $qenddate = date('H:i', strtotime($querys->enddate));

    $individualbids = DB::table('intis_auctions_lots')
            ->select(DB::raw('sum(nrbids) as nbid,lot, startprice,intis_lot_id,product_name,enddate,maxbid'))    
            ->where([['community_name','=',$CommunityNo],['SellerId','=',$SellerId],['active','=','Y'],['startdate','<',$now],['enddate','>',$now],['intis_lot_id','=',$qintis_lot_id]])
            ->groupBy('startprice','intis_lot_id','product_name','lot','enddate','maxbid')
            ->get();   

    foreach($individualbids as $key => $value)
        echo  "<tr><td>".$value->lot."</td>
        <td>".$value->intis_lot_id."</td>
        <td>".$value->product_name."</td>
        <td>".date('H:i', strtotime($value->enddate))."</td>
        <td>".$value->startprice."</td>
        <td>".$value->maxbid."</td>
        </tr>";
    }
}

Check this image

我的查看代码如下

<div class="table-responsive">
    <table id="zero_config" class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>Lot</th>
                <th>Product Name</th> 
                <th>End Time</th>   
                <th>Bids</th>    
                <th>Start Price</th>    
                <th>Current Bid Amount</th> 
                <th>Name</th>
            </tr>
        </thead>
        <tbody>               
            @foreach ($query as $key=>$value) 
                @foreach ($individualbids as $key => $value1)
                    <tr>
                        <td>{{ $value->lot }}</td>
                        <td style="text-align:left">{{ $value->intis_lot_id }},{{ $value->product_name }}</td>
                        <td>{{ date('H:i', strtotime($value->enddate)) }}</td>
                        <td></td>
                        <td>{{ $value1->startprice }}</td>
                        <td>{{ $value->maxbid }}</td>
                        <td></td>
                        <td></td>
                    </tr>
                @endforeach 
            @endforeach 
        </tbody>
        <tfoot>
            <tr>
            </tr>
        </tfoot>
    </table>
</div>

当将其传递给视图时,如下图所示,由于起始价为340,它将所有行的第一个值作为相同的值,但是当我在控制器代码中运行而未传递给查看它显示正确的值。请为我提供在视图中编写正确代码的解决方案,因为这将对我有所帮助。

Check image

0 个答案:

没有答案