title: Create dynamic table in php with mysql data
body: <p>I would to like to create a dynamic table that the rows and columns of the table depends on the data in mysql data. Please see below my codes. </p>
  
  <pre><code>&lt;?php
  require "connect/db.php"; 
  
  $query = mysqli_query($mysqli, "SELECT COUNT(level) level, shelf_no, bin_id FROM location_bin WHERE rack_id =1 GROUP BY shelf_no");
  while($res=mysqli_fetch_array($query)){
  
  $col = $res['level']; //col
  $row = $res['shelf_no']; //rows
  
  echo "&lt;table border='1'&gt;";
  $i = 0;
      while ($i &lt; $col){
          if ($i==$col){
          echo "&lt;tr&gt;";
  
      }
          echo "&lt;td&gt;".$res['bin_id']."&lt;/td&gt;";
          $i++;
      }
      echo "&lt;/tr&gt;";
  echo "&lt;/table&gt;";
  }
  ?&gt;
  </code></pre>
  
  <p>What I want is to display A-1-01 up to A-1-06 in the first row then A-2-01 to A-2-03 on the second row. Note that the data is dynamic.</p>