2016-12-06 151 views
1

我想将两个foreach()循环值合并到一个数组中并将其显示在一个表中。他们都有相同的领域,但我怎么能显示它在一张表中,而不是有两个不同的表?将不同foreach循环的值合并到一个数组中

<tr> 
    <th> ID </th> 
    <th> Transaction Type </th> 
</tr> 
<tbody> 
    <?php 
     $ch = new CommissionHelper($rep); 
     $data = $ch->getTransactionRecords($member); 
     foreach ($data as $record) { 
     $d = ((object)$record); 
     $pt = round($d->point, 2); 
     ?> 
    <tr> 
     <td><?php echo $d->id;?></td> 
     <td><?php echo $d->type;?></td> 
    </tr> 
    <?php 
     } 
     ?> 
</tbody> 
<tr> 
    <th> ID </th> 
    <th> Transaction Type </th> 
</tr> 
<tbody> 
    <?php 
     $query = "SELECT * FROM invoice_withdraw_debit_card where user_ID like $id"; 
     $data = $MySQLi_CON->query($query); 
     foreach ($data as $key) {  
     ?> 
    <tr> 
     <td><?php echo $key['invoice_ID'];?></td> 
     <td><?php echo $key['type'];?></td> 
    </tr> 
    <?php 
     } 
     ?> 
</tbody> 

回答

1

你可以像下面实现它: -

<tr> 
    <th> ID </th> 
    <th> Transaction Type </th> 
</tr> 
<tbody> 
    <?php 
     $ch = new CommissionHelper($rep); 
     $data = $ch->getTransactionRecords($member); 
     foreach ($data as $record) { 
     $d = ((object)$record); 
     $pt = round($d->point, 2); 
     ?> 
    <tr> 
     <td><?php echo $d->id;?></td> 
     <td><?php echo $d->type;?></td> 
    </tr> 
    <?php 
     } 
     ?> 
    <?php 
     $query = "SELECT * FROM invoice_withdraw_debit_card where user_ID like $id"; 
     $data = $MySQLi_CON->query($query); 
     foreach ($data as $key) {  
     ?> 
    <tr> 
     <td><?php echo $key['invoice_ID'];?></td> 
     <td><?php echo $key['type'];?></td> 
    </tr> 
    <?php 
     } 
     ?> 
</tbody> 

注: - 从你的代码

+0

fypforstack很乐意帮助你的中间删除</tbody><tr><th> ID </th><th> Transaction Type </th></tr><tbody>。欢呼:) :) :) –

+0

感谢您的帮助:) – fypforstack

相关问题