the code searches the top entry of a "tree".
I guess you have a table structure like this:
table categry
( categoryid | parentcategoryid | name )
e.g. you have this values in your database:
values
( 1 | 0 | parent )
( 2 | 1 | first_child_to_parent )
( 3 | 1 | second_child_to_parent )
( 4 | 2 | first_child_child_to_first_child )
....
if you start the script with
$childval = 4;
so, the script starts a first time:
- $childval changes to '2'
- $catid[0] is '4'
- $catname[0] is 'first_child_child_to_first_child'
the second time:
- $childval changes to '1'
- $catid[1] is '2'
- $catname[1] is 'first_child_to_parent'
and the third time:
- $childval changes to '0'
- $catid[2] is '1'
- $catname[2] is 'parent'
and then the while loop stops because $childval is '0'.
i guess you have a function to output the values, something like:
rsort($catid);
reset($catid);
while( list($key,$value) = each($catid)) {
echo $catname[$key]."<br>";
}
if your while loop doesn't end it might be that there is no entry with the value '0' in the field 'parentcategoryid' which belongs to the entry you start with!
hth