gpt4 book ai didi

php - foreach inside foreach 比在 HTML Table 中显示它

转载 作者:搜寻专家 更新时间:2023-10-31 21:01:23 25 4
gpt4 key购买 nike

美好的一天。我现在正在尝试创建来 self 的 sql 表的详细信息。

这是我的 PHP:-

public function export()
{
$query = $this->input->cookie("cookie_invent_query");
$data['header'] = $this->modelmodel->showdata($query);
foreach($data['header'] as $header){
$data['detail'][] = $this->modelmodel->showdata("select * from DeliveryOrderDetail
where deliveryordertransno = '".$header->TransactionNo."' ");
}
echo "<pre>"; print_r($data['detail']);
$this->load->view("do_mutasi/export",$data);
}

我在上面的脚本中得到了 print_r()

来自 $data['header'] 的结果

    Array
(
[0] => stdClass Object
(
[FinalReleaseStatus] => 1
[DeliveryOrderDate] => 2016-12-21 17:25:18.487
[TransactionNo] => DO-DL-K-LFKG-11
[DocumentNo] => DOZZ-DL-K-LFKG-6
[ToCustomerCode] => AFF004
[CategoryCode] => ZZ
[ETADate] => 2016-12-21 17:25:18.487
)

)

$data['detail'] 的结果

Array
(
[0] => Array
(
[0] => stdClass Object
(
[TransactionNo] => DOD-DL-K-LFKG-9
[LineNo] => 1000
[ItemCode] => FA00000111
[DeliveryOrderTransNo] => DO-DL-K-LFKG-11
[ExtraRemark] => 0
[ExtraRemark2] => 0
[Quantity] => 3.00000000000000000000
[UOMCode] => PCS
[CreatedDate] => 2016-12-21 17:26:25.063
[CreatedBy] => boby
[ModifiedDate] => 2016-12-21 17:26:25.063
[ModifiedBy] =>
)

)

)

然后在我将它发送到我的 View 之后,这就是我现在可以做的

<?php foreach($header as $hdr) { ?>
Header
<table class="table">
<thead>
<tr>
<th>Trnsaction No</th>
<th>Document No</th>
<th>To Customer</th>
<th>Delivery Order Date</th>
</tr>
</thead>
<tbody>
<td><?=$hdr->TransactionNo;?></td>
<td><?=$hdr->DocumentNo;?></td>
<td><?=$hdr->ToCustomerCode;?></td>
<td><?=$hdr->DeliveryOrderDate;?></td>
</tbody>
</table>
Detail
<table>
<thead>
<tr>
<th>Transaction No</th>
<th>Item Code</th>
<th>Quntity</th>
<th>Uom Code</th>
</tr>
</thead>
<tbody>
<?php

foreach($detail as $rsltdt =>$key) { ?>
<tr>
<td><?=$rsltdt['TransactionNo'];?></td>
<td><?=$rsltdt['ItemCode'];?></td>
<td><?=$rsltdt['Quantity'];?></td>
<td><?=$rsltdt['UOMCode'];?></td>
</tr>
<?php } ?>
</tbody>
</table>

<?php } ?>

如你所见。我在 header 循环中循环 detail。因为在一些记录中有多个细节。我循环 header 是因为我想向它显示多个 records 而不仅仅是一个 record

这是目前的结果

enter image description here

我不能显示细节。所以我的问题是。我如何显示详细信息取决于标题。

[TransactionNo] = [DeliveryOrderTransNo]

最佳答案

检查一次:-

foreach($detail as $rsltdt) { 
foreach ($rsltdt as $rsl){ ?>
<tr>
<td><?=$rsl->TransactionNo;?></td>
<td><?=$rsl->ItemCode;?></td>
<td><?=$rsl->Quantity;?></td>
<td><?=$rsl->UOMCode;?></td>
</tr>
<?php } } ?>

关于php - foreach inside foreach 比在 HTML Table 中显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41518368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com