Hi.
How do I return a string containing an entire menu-tree from a
recursive function?
Here is my current recursive function:
function page_tree( $_i ){
//Call global mysql connection variable
global $_conn;
//SQL statement
$_sql = "SELECT page_tree . * , document . * FROM page_tree
INNER JOIN document ON document.d_id = page_tree.p_document_id
WHERE (page_tree.p_parent_id = ".$_i.")
ORDER BY page_tree.p_id";
//Query
$_q = mysql_query( $_sql, $_conn );
//Check for number of returned rows
if( mysql_num_rows( $_q ) )
{
//While there is content
while( $_r = mysql_fetch_array( $_q ) )
{
print "<a href=". $_r['d_file_name'] .">".$_r['d_link_text']."</a>";
//Recursive function call
page_tree( $_r['p_id'] );
}
}
//Release query
mysql_free_result( $_q );
}//page_tree( $_i )
This will generate a file list of all the content in the db in a
tree-like structure.
My Problem is that what I want should look more like this:
<ul>
<li>Front page</li>
<li>Second page
<ul>
<li>Second page, 1. sublevel</li>
<li>Second page, 2. sublevel
<ul><li>Second page, 2. sublevel</li></ul>
</li>
<li>Second page, 1. sublevel</li>
</lu>
</li>
<li>Second page</li>
</ul>
How do I go about returning a string that looks like the one above?
The recursive idea is no demand, it's just an idea.