title: PHP array into HTML table
body: <p>I am trying to show all products in a database with a certain category in a HTML table. However I'm not sure how to limit the table to three columns only. </p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;table&gt;
      &lt;?php
    $catagory=$_GET["q"];
  
  
  $con = mysql_connect("localhost","cl49-XXX","XXX");
  if (!$con) 
    {
     die('Could not connect: ' . mysql_error());
     }
  
  mysql_select_db("cl49-XXX", $con)or die( "Unable to select database");
  
  
  $result=mysql_query("SELECT * FROM products WHERE catagory  = '$catagory' ")or die('You need enter a catagory ' );
  
    for ($i = 0; $i &lt; mysql_num_rows($result); $i++)
      {
          $row = mysql_fetch_array($result);
  
          $prodname = $row['prodname'];
          $prodID = $row['prodID'];
          if ($i % 5 == 0 || $i == 0) {
              echo "&lt;tr&gt;";
          }
          echo "
          &lt;td&gt;
              &lt;b&gt;$prodname &lt;/b&gt;&lt;br /&gt;
              Product ID: $prodID&lt;br /&gt;
              &lt;img src='/userpics/$prodID.jpg' height='200' width='200'&gt;
          &lt;/td&gt;";
  
          if ($i % 3 == 0 || $i == (mysql_num_rows($result)-1)) {
              echo "&lt;/tr&gt;";
          }
      }
      ?&gt;
  &lt;table&gt;
  </code></pre>
  
  <p>I am waiting to show prodID, prodtitle and image all in the same "cell" but only have three columns (three products per row).</p>
  
  <p>How do I do this?</p>