title: Show all data from Mysql Database by category wise using php
body: <p>Currently in my php code I'm getting all <code>keywords</code> from a mysql table and showing it on a Html <code>td</code> column. It looks like the one in the following image. </p>
  
  <p><img src="https://i.stack.imgur.com/WPGZi.gif" alt="enter image description here"></p>
  
  <p>Each <strong>keyword</strong> has an unique <strong>keyword type</strong>. For example it may contain php, html css, js under <strong>Web Development</strong> Keyword type.</p>
  
  <p>So Now, I'm only printing all Keywords, not their <strong>Keyword Type</strong>.</p>
  
  <p>I need to show <strong>keywords</strong> under each <strong>keyword type</strong>. So it should look like this : </p>
  
  <pre><code>Keyword Type1     Keyword Type2    Keyword Type3   Keyword Type4  and so on...           
  html              wp               js              php 
  mysql             html5            jquery          c
  css               css3             xml             c++
  </code></pre>
  
  <p>How can I show this in php ?</p>
  
  <p><strong>My existing php code is the following :</strong></p>
  
  <pre><code>&lt;?php
  $query =  mysql_query("SELECT keywords . *, keyword_type . * FROM keywords LEFT JOIN keyword_type ON keywords.keyword_typeID = keyword_type.keyword_typeID  ORDER BY kid DESC");
  echo "&lt;div id='keywordBox'&gt;";
  
  echo '&lt;table border="0" cellpadding="0" cellspacing="0" width="1055"&gt;';
  $count = 0;
  while($result =  mysql_fetch_array($query)){
  
    if($count%6==0 &amp;&amp; $count!=0){    
      echo "&lt;/tr&gt;&lt;tr&gt;";
    }elseif($count==0)
      echo "&lt;tr&gt;";
  
      $kid = $result['kid'];
      $keywordName = ucfirst($result['keywordName']);
      $keyword_short_name = ucfirst($result['keyword_short_name']); // keyword type
      $keyword_full_name = ucfirst($result['keyword_full_name']);  // keyword type full name 
  
      $query2 =  mysql_query("SELECT kid FROM userkeywords WHERE cdid = '$cdid' AND kid='$kid'");
      $num=mysql_num_rows($query2);
  
      if($num &gt; 0){
          $class = "keywordHigligh";  
      }else{
          $class = "";
      }
  
      echo "&lt;input type='hidden' id='kid' value='$kid'/&gt;";    
      echo "&lt;input type='hidden' id='cdid' value='$cdid'/&gt;";  
      echo "&lt;td width='400' onclick='keywordclick($kid,$cdid)' class='$class'&gt;&lt;strong&gt;$keywordName&lt;/td&gt;";
  
      $count++;  
  }
  
  echo '&lt;/table&gt;';
  echo "&lt;/div&gt;";
  echo "&lt;a href='../index.php?redcdid=$cdid'&gt;&lt;input type='submit' value='Save' class='submit' /&gt;&lt;/a&gt;"
  ?&gt;
  </code></pre>
  
  <p><strong>Note:</strong></p>
  
  <pre><code>$keyword_short_name = ucfirst($result['keyword_short_name']); // keyword type
  $keyword_full_name = ucfirst($result['keyword_full_name']);  // keyword type full name 
  </code></pre>
  
  <p>Thanks for your suggestion and help. --Shibbir</p>