title: Create Html table in php foreach loop
body: <p>I'm facing a problem which i had create a html table in &quot;Php foreach loop&quot; to loop from Mysql data into the html table.
  <br/>
  But when i have more than 1 row of data, it wont show in the same table but turn out to each row of data show in independent table.</p>
  <pre><code>&lt;?php
      global $wpdb, $indeed_db;
      $user = wp_get_current_user();
      $userid = $user-&gt;ID; 
      $woo_orders = $wpdb-&gt;get_results(&quot;SELECT * FROM wp8u_wc_order_product_lookup&quot;);
      foreach ($woo_orders as $print ){
          $order_id = $print-&gt;order_id; 
          $woo_customer_id = $print-&gt;customer_id;  
          $woo_customer = $wpdb-&gt;get_results(&quot;SELECT * FROM wp8u_wc_customer_lookup where customer_id=$woo_customer_id&quot;);
          foreach($woo_customer as $print2){
              $current_user_uid = $print2-&gt;user_id;
          }
          $date1 = strtotime($print-&gt;date_created);
          $date_created = date('Y-m-d H:i:s', $date1);                                                                      
          $amount = $print-&gt;product_net_revenue;                                                                      
          if($userid == $current_user_uid){ ?&gt;
                  &lt;table&gt;
                      &lt;thead&gt;
                          &lt;tr&gt;
                              &lt;th&gt;Order ID&lt;/th&gt;
                              &lt;th&gt;My Customer ID&lt;/th&gt;
                              &lt;th&gt;Create Date&lt;/th&gt;
                              &lt;th&gt;Amount&lt;/th&gt;
                          &lt;/tr&gt;
                      &lt;/thead&gt;
                      &lt;tbody&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;?php echo &quot;$order_id&quot;;?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo &quot;$woo_customer_id&quot;;?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo &quot;$date_created&quot;;?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo &quot;$amount&quot;;?&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/tbody&gt;
                      &lt;/table&gt;
          &lt;?php }
  }
  ?&gt;
  </code></pre>
  <p>The output:</p>
  <pre><code>Order ID | My Customer ID |    Create Date         |   Amount   |
  126        9                   2020-06-24 13:45:35     3000        &lt;-- 1st row data
  Order ID | My Customer ID |    Create Date         |   Amount   |
  123        9                   2020-06-22 12:01:14     1000        &lt;-- 2nd row data show in independent table
  </code></pre>
  <p>After doing some research, I try using this method but it turn out to the table only store 1st row of data, 2nd and after of row data show out side of the table instead of showing inside the table</p>
  <pre><code>&lt;?php
      global $wpdb, $indeed_db;
      $user = wp_get_current_user();
      $userid = $user-&gt;ID; 
      ?&gt;
      &lt;table&gt;
          &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;Order ID&lt;/th&gt;
                  &lt;th&gt;My ID&lt;/th&gt;
                  &lt;th&gt;Create Date&lt;/th&gt;
                  &lt;th&gt;Amount&lt;/th&gt;
              &lt;/tr&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
      &lt;?php
      $woo_orders = $wpdb-&gt;get_results(&quot;SELECT * FROM wp8u_wc_order_product_lookup&quot;);
      foreach ($woo_orders as $print ){
          $order_id = $print-&gt;order_id; 
          $woo_customer_id = $print-&gt;customer_id;  
          $woo_customer = $wpdb-&gt;get_results(&quot;SELECT * FROM wp8u_wc_customer_lookup where customer_id=$woo_customer_id&quot;);
          foreach($woo_customer as $print2){
              $current_user_uid = $print2-&gt;user_id;
          }
          $date1 = strtotime($print-&gt;date_created);
          $date_created = date('Y-m-d H:i:s', $date1);                                                                      
          $amount = $print-&gt;product_net_revenue;                                                                      
          if($userid == $current_user_uid){ ?&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;?php echo &quot;$order_id&quot;;?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo &quot;$woo_customer_id&quot;;?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo &quot;$date_created&quot;;?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;?php echo &quot;$amount&quot;;?&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/tbody&gt;
          &lt;/table&gt;
          &lt;?php }
  }
  ?&gt;
  </code></pre>
  <p>The output:</p>
  <pre><code>Order ID |  My ID | My Customer ID |    Create Date         |   Amount   | 
  126         37          9               2020-06-24 13:45:35     3000       &lt;-- 1st row data         
  
  123 9 2020-06-22 12:01:14 2020-07-22 12:01:14 1000                         &lt;-- 2nd row data show outside of the table
  </code></pre>