Following is a mysql table named "readcontent_categories"
I want to produce a tree of indefinite depth using the above table. For example let I want to see everything under "english". Then it must show as below:
english
|--------+Tens
|-------+present
|-------+past
|-------+future
Now I tried as below :
<?php
include("config.php");
$query = "SELECT * FROM readcontent_categories";
$result = mysql_query($query);
function getChildren($pid){
$r = array();
global $row, $result;
while( $row = mysql_fetch_array($result) ){
if($row['parent_id'] == $pid)$r[$row['id']] = getChildren($row['id']);
}
return $r;
}
$final = getChildren(1);
print_r($final);
?>
So am I doing it write? How can I get an output as above ? The output I am getting is not as expected. My output is as below:
Array ( [2] => Array ( [3] => Array ( ) ) )
But how can the above output is obtained? Anybody can help???