duandong1869 2016-12-06 07:14
浏览 91
已采纳

将来自不同foreach循环的值组合到一个数组中

I am trying to combine two foreach() loop values into an array and display it in a single table. Both of them have the same field, but how can i display it in a single table instead of having two different tables?

<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条回答 默认 最新

  • dtry54612 2016-12-06 07:20
    关注

    You can achieve it like below:-

    <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>
    

    Note:- remove </tbody><tr><th> ID </th><th> Transaction Type </th></tr><tbody> from the middle of your code

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料