title: Display mysql data in formatted table
body: <p>I am retrieving data from a database and displaying in a table. I would like the table to be in a 4 x 3 layout. The data retrieves just fine, it's the layout that isn't working.  Here is my code:</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  
  $db = new mysqli('localhost', 'root', '', 'ezwayautos');
  
  if($db-&gt;connect_errno &gt; 0){
      die('Unable to connect to database [' . $db-&gt;connect_error . ']');
  }
  $sql = "SELECT * FROM vehicles ORDER BY RAND() LIMIT 12";
  
  if(!$result = $db-&gt;query($sql)){
      die('There was an error running the query [' . $db-&gt;error . ']');
  }
      echo "&lt;table&gt;";
  while($row = $result-&gt;fetch_assoc())
  {
      echo "&lt;tr&gt;";
      echo "&lt;td height='160' valign='top' class='featured'&gt;";
      echo "&lt;div class='Image-Thumbnail'&gt;";
      echo "&lt;a href=''&gt;";
      echo "&lt;img src='".$row['image']."' width='160' height='54'&gt;";
      echo "&lt;/a&gt;";
      echo "&lt;/div&gt; &lt;a href=''&gt;" .$row['vehicle_name']. "&lt;/a&gt;";
      echo "&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  }
      echo "&lt;/table&gt;";
  ?&gt;
  </code></pre>
  
  <p>What is supposed to go in each cell is a picture of the vehicle with the name underneath the picture.</p>
  
  <p>Here is an example from another website as to how I would like it to look:</p>
  
  <p><a href="http://www.denisonmotors.com" rel="nofollow">http://www.denisonmotors.com</a></p>
  
  <p>I am not stealing any information from their site I am just trying to get my data to display in the format that they have on their site.</p>
  
  <p>I am not concerned about the empty href tag as they will be filled in later.</p>
  
  <p><strong>After doing some research, I think that I have to use 2 for loops to create the table stating how many columns and row that I want.</strong></p>