Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
PHP Display Category Subcategory Tree View
Sponsered Links
Sponsered Links

PHP Display Category Subcategory Tree View

This example illustrates how to display category sub-category in tree view.

    print "<select name='catId' class='required'>";
    print "<option value=''>Select Category</option>";
    $selcat = "SELECT * from category order by name ASC";
    $selcat2 = mysql_query($selcat) or die("Could not select category");
    traverse(0, 0, $selcat2);
    print "</select><br>";
    function traverse($root, $depth, $sql) {
        while ($acat = mysql_fetch_array($sql)) {
            if ($acat['parentID'] == $root) {
                print "<option value='" . $acat['id'] . "'>";
                while ($j<$depth) {    
                    print "&nbsp;&nbsp;&nbsp;&nbsp;";
                    print ">>&nbsp;";
                print $acat['name'] . "</option>";
                traverse($acat['id'], $depth+1,$sql);

Sponsered Links
Latest Updates
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved