PHP基于父级显示类别

I have been fighting with this issue for about 2 months now and I still have not found a solution.

I am very new to PHP/MYSQL so please be easy / patient.

Basically, I have a page, called "browse.php" - This page has a query, which selects * from table and lists the categories AS A TREE.

What I actually need it to do, is ONLY list categories with a parent of "0".

When one of these categories are clicked, it should take you to a new page (lets call this page browse2.php) which then lists ONLY the categories for the parent of "CATID clicked on browse.php)

MYSQL DB:

    CREATE TABLE `categories_docs` (
    `CATID` bigint(20) NOT NULL AUTO_INCREMENT,
    `name` varchar(120) NOT NULL DEFAULT '',
    `parent` bigint(20) NOT NULL DEFAULT '0',
     PRIMARY KEY (`CATID`),
     UNIQUE KEY `name` (`name`)
     ) ENGINE=MyISAM AUTO_INCREMENT=22 DEFAULT CHARSET=utf8

BROWSE.php:

   <?php

   error_reporting(E_ALL);
   ini_set('display_errors', '1');

   function display_children($parent) { 
       $result = mysql_query('SELECT * FROM categories_docs '. 
                        'WHERE parent="'.$parent.'";'); 
        // display each child 
        echo "<ul>";
        while ($row = mysql_fetch_array($result)) { 
            echo "<li class='child'><a href='browse2.php?cat=".$row['CATID']."'>".$row['name']."</a></li>"; 
        } 
        echo "</ul>";
    } 
    $result = mysql_query('SELECT * FROM categories_docs WHERE parent= 0'); 
    echo "<div id='cat_cont' >"; 
    while ($row = mysql_fetch_array($result)) {
        echo "<div class='parent' align='left'><a href='ads.php?cat=".$row['CATID']."' >".$row['name']."</a></div>";
    }
    echo "</div>";

     ?>

I am really looking forward to one of you gurus being able to help me.

Thanks in advance!

First off, you should really use PDO or mysqli commands, using mysql queries isn't really concidered 'good practice' nowadays.

As for your problem: For getting your parent categories only:

SELECT * from categories_docs WHERE parent=0

In your 'sub'page:

SELECT * from categories_docs WHERE parent=$parentID