title: Displaying Moodle database data as ul li using php
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7673044/nested-array-third-level-is-disappearing">Nested array. Third level is disappearing</a>  </p>
  </blockquote>
  
  
  
  <p>I kinda have a problem here with displaying moodle database data as ul li form using php.
  I want to display all the categories of courses, not courses, in their proper nested form as ul li.
  The table I'm working on is mdl_course_categories.
  Whenever the php script runs, the list must be updated dynamically
  The code looks as shown:</p>
  
  <pre><code>&lt;?php
  $con = mysql_connect("localhost","root","");
  if (!$con) {
  die('Could not connect: ' . mysql_error());
  }
  
  mysql_select_db("moodle19", $con);
  $result = mysql_query("SELECT name AS COURSE_NAME,parent FROM mdl_course_categories");
  
  if (isset($result)!=1) {
  $message  = 'Invalid query: ' . mysql_error() . "\n";
  }
  echo "&lt;p&gt; The courses taught are: &lt;/p&gt;";
  
  while ($row = mysql_fetch_array($result)) {
  $b=$row['COURSE_NAME'];
  $c=$row['parent'];
  
  //      $a=mysql_query("Select id from mdl_course_categories");
  //      $condition=mysql_query("SELECT name AS COURSE_NAME FROM mdl_course_categories WHERE parent='0'");
  
      if ($c==0) {
      echo "&lt;ul&gt;
      &lt;li&gt;" .$b. "&lt;/li&gt;
      &lt;/ul&gt;";
      }
  
      else {
          echo "&lt;ul&gt;
              &lt;li&gt;" .$b. "&lt;/li&gt;
              &lt;/ul&gt;";
      $result1 = mysql_query("SELECT name AS COURSE_NAME FROM mdl_course_categories WHERE depth!='1'");
      while ($row1 = mysql_fetch_array($result1)) {
  
          $b1=$row1['COURSE_NAME'];
          echo "&lt;ul&gt;
              &lt;li&gt;" .$b1. "&lt;/li&gt;
              &lt;/ul&gt;";
          }
      }   
  }
  ?&gt;
  </code></pre>
  
  <p>I have confusion in understand what is going wrong?</p>