这是我查询的输出集合
[{delivery_date: "2019-01-09", delivery_count: "5", price: "190.00", total_price: "950.00"}
{delivery_date: "2019-01-10", delivery_count: "45", price: "170.00", total_price: "7650.00"}
{delivery_date: "2019-01-10", delivery_count: "2", price: "50.00", total_price: "100.00"}
{delivery_date: "2019-01-10", delivery_count: "3", price: "60.00", total_price: "180.00"}
{delivery_date: "2019-01-10", delivery_count: "3", price: "185.00", total_price: "555.00"}
{delivery_date: "2019-01-16", delivery_count: "6", price: "50.00", total_price: "300.00"}]
这就是我查询表的方式
$deliveries = DB::table('deliveries')
->where('user_id',Auth::id())
->groupBy('price','delivery_date')
->orderBy('delivery_date')
->select('delivery_date',DB::raw('SUM(number) as delivery_count'),'price', DB::raw('SUM(number*price) as total_price'))
->get();
这就是我显示数据的方式
<table class="display table table-condensed table-bordered">
<thead>
<th>Date</th>
@foreach($deliveries as $delivery)
<th>{{$delivery->price}}</th>
@endforeach
</thead>
<tbody>
@foreach($deliveries as $delivery)
<tr>
<td>{{ $delivery->delivery_date }}</td>
@if($delivery->price = $deliveries[$i]->price)
<td>{{ $delivery->delivery_count }}</td>
@else
<td>0</td>
@endif
</tr>
@endforeach
</tbody>
</table>
这就是我的看法
我被困在这里,仍在尝试找出方法。.请帮助。 谢谢大家!