Tree
ID | Parent ID | Name |
3 | 1 | Countries |
4 | 3 | Belgium |
5 | 3 | Netherlands |
6 | 3 | Germany |
7 | 5 | Business |
8 | 5 | Economy |
Retrieving the full path to the root node goes with something like:
<?php
function collectPath( $id ) {
global $dir;
$res = mysql_query( "SELECT parent, name FROM dir WHERE id=$id" );
if ( mysql_num_rows( $res ) > 0 ) {
$dir[] = ( $row = mysql_fetch_row( $res ) );
collectPath( $row['parent'] );
}
}
$dir = array();
collectPath(7);