I did implement it as you can see here
<?php
function fetch_results($value=''){
//Get first results
$array = array();
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db('data_guide');
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
$sql = "SELECT * from category WHERE parent_id = $value";
$result = mysql_query( $sql ) ;
if (!$result) {
die('Invalid query: ' . mysql_error());
}
$i = 0;
//$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[$i]['category_id'] = $row['category_id'];
$rows[$i]['category_name'] = $row['category_name'];
$rows[$i]['parent_id'] = $row['parent_id'];
$i++;
}
//print_r($rows);
/Now $rows should be a multi-array with your mySQL result in it. FOR is your friend, while is a tosser/
for($i=0;count($rows)>$i;$i++){
if(empty($rows[$i]['category_id'])) continue;
$array[$i] = $rows[$i];
$result = fetch_results($rows[$i]['category_id']);
print $result;
if(empty($result)) continue;
$array[$i]['sub'] = $result;
}
return $array;
}
print("<pre>");
print_r(fetch_results(0));
?>
but I think it is making to many database queries, don't you?