title: generating links for nested menu using php and mysql
body: <p>I have went through dozens and dozens of similar questions, but non that actually tackle my specific requirement.</p>
  
  <p>I have a mysql table that are defined by three variables (id, name, pid)</p>
  
  <p>The nested menu is generated with the following function:</p>
  
  <pre><code>function get_categories($parent = '0') {
      $html = '&lt;ul id="menu"&gt;';
      $query = mysql_query("SELECT * FROM `categories` WHERE `pid` = '$parent'");
      while($row = mysql_fetch_assoc($query)) {
          $current_id = $row['id'];
          $html .= '&lt;li&gt;&lt;a href=""&gt;' . $row['name'] . '&lt;/a&gt;';
          $has_sub = NULL;
          $has_sub = mysql_num_rows(mysql_query("SELECT COUNT(`pid`) FROM `categories` WHERE `pid` = '$current_id'"));
          if($has_sub) {
              $html .= get_categories($current_id);
          }
          $html .= '&lt;/li&gt;';
      }
      $html .= '&lt;/ul&gt;';
      return $html;
  }
  print get_categories();
  </code></pre>
  
  <p>My question is how I may generate the link so that it is presented in a 'pretty url' manner.
  ex. <code>&lt;a href="/parent_category/sub_category/sub_sub_category"&gt;</code>?
  Any help will be really appreciated.</p>