title: loop to populate html table vertically
body: <p>I have a mysql query that returns an array of rows. How would i populate my html table using php vertically? there is no limit to how many columns i my HTML table allowed.</p>
  
  <p>My MYSQL query returns about 40 columns per row.</p>
  
  <pre><code>MYSQL row1 =&gt;  10|11|12|13|14|15|16|17|18|19
        row2 =&gt;  20|21|22|23|24|25|26|27|28|29
        row3 =&gt;  30|31|32|33|34|35|36|37|38|39
  </code></pre>
  
  <p>HTML output should look like this</p>
  
  <pre><code>   10 | 20 | 30
     11 | 21 | 31
     12 | 22 | 32
     13 | 23 | 33
     14 | 24 | 34
     15 | 25 | 35
     16 | 26 | 36
     17 | 27 | 37
     18 | 28 | 38
     19 | 29 | 39
  </code></pre>
  
  <p>this is my code, and it's displaying nothing.</p>
  
  <pre><code>$values = array();
  
  $sql = "SELECT * FROM `TABLE_NAME` ORDER BY `id` ASC LIMIT 0,12";
  $result = $_db-&gt;query($sql);
  
  $numrows = $_db-&gt;num_rows($result);
  
  $c = 1;
  while ($c &lt;= $numrows)
  {
      $values['col_'.$c] = array(); 
      $c++;
  }
  
  $r = 1;
  
  while ($row = $_db-&gt;fetch_array($result)) 
  {
      $values['col_'.$c][$r] = $row;
  
      $r++; 
  }
  echo "&lt;table border='1'&gt;";
  
  
  for ($r = 1; $r &lt;= $numrows; $r++) 
  {
      echo "&lt;tr&gt;";
      for ($c = 1; $c &lt;= sizeof($values['col_1']); $c++) 
      { 
          echo "&lt;td&gt;".$values['col_'.$c][$r]."&lt;/td&gt;"; 
      }
      echo "&lt;/tr&gt;" ;
  }
  echo "&lt;/table&gt;" ;
  </code></pre>
  
  <p>Any idea what i'm doing wrong? or how to make it simpler? (i think there are too many while loops) </p>