title: Create html table using php using group by
body: <p>My mysql database has the following:</p>
  
  <pre><code>productid | productname | category
      1            XYZ         News
      2            ZYX         News 
      3            vcb         Info 
  </code></pre>
  
  <p>I want to display them in a table group by category like this</p>
  
  <pre><code>Category : News
  xyz 
  zyx
  
  Category : Info
  vcb
  
  Etc....
  </code></pre>
  
  <p>currently i am using </p>
  
  <pre><code>$sql="SELECT * FROM database Group By category";
  $result = mysql_query($sql);
  if(mysql_num_rows($result) &gt; 0) {
  
  
  echo "&lt;table cellspacing='0' cellpadding='0'&gt;
  &lt;thead&gt;
  &lt;tr&gt;
  &lt;th&gt;id&lt;/th&gt;
  &lt;th&gt;name&lt;/th&gt;
  &lt;th&gt;catergory&lt;/th&gt;
  
  &lt;/tr&gt;
  &lt;/thead&gt;";
  
  $i = 0;
  
  while($row = mysql_fetch_array($result))
    {
      if($i%2 == 0)
     {
        $class = 'even';
     }
     else
     {
        $class = 'odd';
     }
  
    {
    echo "&lt;tbody&gt;";
    echo "&lt;tr class='$class'&gt;";
     echo "&lt;td&gt;" . $row['productid'] . "&lt;/td&gt;";
  echo "&lt;td style='font-weight: bold; text-align: center;'&gt;" . $row['productname '] . "&lt;/td&gt;"; 
  echo "&lt;td style='font-weight: bold; text-align: center;'&gt;" . $row['category '] . "&lt;/td&gt;";     
    echo "&lt;/tr&gt;";
   }
         $i++;
      }
  
  echo "&lt;/tbody&gt;";
  echo "&lt;/table&gt;";
  } else {
      echo "";
  }
  </code></pre>