title: Getting sub categories from mysql for the main category
body: <p>I am having some problem in retrieving sub categories from mysql database.I want to display the sub-categeories for the parent categories.<strong>I am able to get only the last sub category of a main category. The first sub-categories are not displaying **. In my table **i have category_id and category_parent_id.where category_parent_id will be '0' for parent category.</strong> .Thanks in advance </p>
  
  <pre><code> &lt;ul class="betterList"&gt;
   &lt;?php 
          $con = mysql_connect("localhost","root","pwd") or die('couldnot connect to database'.mysql_error());
                 mysql_select_db("DB",$con);
                 $result=mysql_query("select * from table ")or die("No table available with this name"."&lt;br/&gt;&lt;br/&gt;".mysql_error());
               while($row=mysql_fetch_array($result))
                 {
                  $parent_id=$row['category_parent_id'];
                  $category_id=$row['category_id'];
                  if($parent_id==0)
  
                  {
  ?&gt;
                  &lt;li&gt;
                  &lt;?php echo $row['category_id'].$row['name_en-GB'];
  
                  $result1=mysql_query("select * from table where category_parent_id=".$category_id)or die("No data available with this name"."&lt;br/&gt;&lt;br/&gt;".mysql_error());
                   echo  $num_row    = mysql_num_rows($result1);
  
                      if($num_row&gt;0) {
                          for($i=0;$i&lt;$num_row;$i++)
                          {
                               while($row1=mysql_fetch_array($result1))
                               {
  
                    ?&gt;
                                       &lt;ul style="margin:0px;padding:0;"&gt;
                                          &lt;li&gt;&lt;?php echo $row1['name_en-GB']?&gt;&lt;/li&gt;
                                       &lt;/ul&gt;
                                       &lt;?php
                               }
                          }
                      }
  
                  ?&gt;
  
  
                  &lt;/li&gt;
  
                  &lt;?php } ?&gt;
  
  
  
      &lt;?php }?&gt; 
   &lt;/ul&gt;
  </code></pre>
  
  <p>when i remove <code>&lt;li&gt;</code> tag which is at the end and keep it after at the end of  in while i could display all the sub-catgeories but the css is not applying for that. Some thing is going wrong there but i couldn't figuer it out</p>