1

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

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

fypforstack glad to help you. Cheers :):):)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.