【发布时间】:2016-05-26 03:02:53
【问题描述】:
我是编程界的新手。我正在尝试使用 laravel5.1 创建一个应用程序。我有一堆数据作为多维数组。现在我想用这些数据创建一个表。返回数据如下:
[
[
{ "id":581,"user_id":101,"amount":"500.00","charge":"10.00", "rcvd_account":"01916811723","account_type":"personal","acc_carrier":"bKash","req_date":"2016-04-26 12:46:43","response_date":"2016-05-24 15:41:40","remark":"","tnx_id":"bkp_71535117","status":1,"processed_by":"824"},
{"id":712,"user_id":429,"amount":"200.00","charge":"10.00","rcvd_account":"01723214356","account_type":"personal","acc_carrier":"bKash","req_date":"2016-05-01 23:05:00","response_date":"2016-05-24 15:40:53","remark":"Mon chaise tai","tnx_id":"bkp_30513790","status":2,"processed_by":"824"},
{"id":995,"user_id":17,"amount":"2000.00","charge":"100.00","rcvd_account":"01819529861","account_type":"agent","acc_carrier":"dbblm","req_date":"2016-05-24 17:30:25","response_date":"2016-05-24 17:30:51","remark":"","tnx_id":"dbma_18209839","status":1,"processed_by":"824"}
],
[
{"id":1004,"user_id":560,"amount":"1200.00","charge":"24.00","rcvd_account":"0191125478","account_type":"personal","acc_carrier":"dbblm","req_date":"2016-05-24 19:30:54","response_date":"2016-05-24 19:36:35","remark":"Account balance and transaction amount mismatch. Account balance is BDT 9000 grater than transaction amount.","tnx_id":"dbmp_98010253","status":2,"processed_by":"824"}
],
[
{"id":1005,"user_id":598,"amount":"5000.00","charge":"250.00","rcvd_account":"01819529861","account_type":"agent","acc_carrier":"bKash","req_date":"2016-05-24 19:32:40","response_date":"2016-05-24 19:36:37","remark":"","tnx_id":"bka_89541626","status":1,"processed_by":"824"},
{"id":1006,"user_id":598,"amount":"1980.00","charge":"10.00","rcvd_account":"01911205478","account_type":"personal","acc_carrier":"bKash","req_date":"2016-05-24 19:33:24","response_date":"2016-05-24 19:36:51","remark":"","tnx_id":"bkp_64898681","status":1,"processed_by":"824"},
{"id":1007,"user_id":598,"amount":"5000.00","charge":"250.00","rcvd_account":"0185421365","account_type":"agent","acc_carrier":"dbblm","req_date":"2016-05-24 19:33:44","response_date":"2016-05-24 19:36:53","remark":"","tnx_id":"dbma_8505249","status":1,"processed_by":"824"},
{"id":1008,"user_id":598,"amount":"2000.00","charge":"100.00","rcvd_account":"0214214521","account_type":"agent","acc_carrier":"dbblm","req_date":"2016-05-24 19:34:02","response_date":"2016-05-24 19:36:49","remark":"Account balance and transaction amount mismatch. Account balance is BDT 15240 grater than transaction amount.","tnx_id":"dbma_97558593","status":2,"processed_by":"824"},
{"id":1009,"user_id":598,"amount":"200.00","charge":"4.00","rcvd_account":"018954213652","account_type":"personal","acc_carrier":"dbblm","req_date":"2016-05-24 19:34:41","response_date":"2016-05-24 19:36:54","remark":"","tnx_id":"dbmp_21560669","status":1,"processed_by":"824"}
]
]
我想创建一个如下表:
<table class="table m-t-40">
<thead>
<tr>
<th>#</th>
<th>Purpose</th>
<th>DC</th>
<th>Amount</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Withdrawl Balance</td>
<td>satataunit</td>
<td>bKash</td>
<td>500.00</td>
<td rowspan="3">2700</td>
</tr>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>satataunit</td>
<td>bKash</td>
<td>200.00</td>
</tr>
<tr>
<td>3</td>
<td>Withdrawl Balance</td>
<td>satataunit</td>
<td>dbblm</td>
<td>2000.00</td>
</tr>
<tr>
<td>4</td>
<td>Withdrawl Balance</td>
<td>mahienterprise</td>
<td>dbblm</td>
<td>1200.00</td>
<td rowspan="1">1200</td>
</tr>
<tr>
<td>5</td>
<td>Withdrawl Balance</td>
<td>mizanur</td>
<td>bKash</td>
<td>5000.00</td>
<td rowspan="5">14180</td>
</tr>
<tr>
<td>6</td>
<td>Withdrawl Balance</td>
<td>mizanur</td>
<td>bKash</td>
<td>1980.00</td>
</tr>
<tr>
<td>7</td>
<td>Withdrawl Balance</td>
<td>mizanur</td>
<td>dbblm</td>
<td>5000.00</td>
</tr>
<tr>
<td>8</td>
<td>Withdrawl Balance</td>
<td>mizanur</td>
<td>dbblm</td>
<td>2000.00</td>
</tr>
<tr>
<td>9</td>
<td>Withdrawl Balance</td>
<td>mizanur</td>
<td>dbblm</td>
<td>200.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="4">Total</th>
<th >18080</th>
</tr>
</tfoot>
</table>
我正在尝试以下代码:
$total = 0;
$sn = 0;
foreach($results as $key => $element) {
$sn++;
for($i=0; $i<count($element); $i++){
$total += $element[$i]->amount;
$table .= "<tr><td>".$sn."</td><td>Withdrawl Balance</td><td>". AppHelper::getDc($element[$i]->user_id) ."</td><td>". $element[$i]->acc_carrier ."</td><td>". $element[$i]->amount. (end($element) ? '</td><td rowspan="'.count($element).'">'.$total.'</td>': '')."</tr>";
}
$table .= "</tbody></table>";
我的输出数据如下:
<table class='table m-t-30'>
<thead>
<tr>
<th>#</th>
<th>Purpose</th>
<th>DC</th>
<th>Acc. Carrier</th>
<th>Amount</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>arifdc</td>
<td>dbblm</td>
<td>560.00</td>
<td rowspan="2">560</td>
</tr>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>arifdc</td>
<td>bKash</td>
<td>350.00</td>
<td rowspan="2">910</td>
</tr>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>mahienterprise</td>
<td>bKash</td>
<td>1200.00</td>
<td rowspan="6">2110</td>
</tr>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>mahienterprise</td>
<td>dbblm</td>
<td>2000.00</td>
<td rowspan="6">4110</td>
</tr>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>mahienterprise</td>
<td>dbblm</td>
<td>1000.00</td>
<td rowspan="6">5110</td>
</tr>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>mahienterprise</td>
<td>bKash</td>
<td>1520.00</td>
<td rowspan="6">6630</td>
</tr>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>mahienterprise</td>
<td>bKash</td>
<td>1980.00</td>
<td rowspan="6">8610</td>
</tr>
<tr>
<td>2</td>
<td>Withdrawl Balance</td>
<td>mahienterprise</td>
<td>dbblm</td>
<td>3500.00</td>
<td rowspan="6">12110</td>
</tr>
</tbody>
这是“rowspan”的问题,它没有按预期设置。请高手帮我看看问题出在哪里?请告诉我如何才能达到我的预期目标?提前谢谢亲爱的
【问题讨论】:
-
您要解决的具体问题是什么?