Sorry guys back again with my recursive array which does work but I cannot get the "layout" right what I am after is a "proper" tree structure using <ul>,<li> so you end up like this:
- Item
- Child
- Child of child
- Etc...
- Child of child
- Child
My function looks like this - whilst the function works the "layout" does not suggestions please.
function recursive_array($results,$tbl) {
global $DBH;
$tbl = $tbl;
if (count($results)) {
foreach($results as $res) {
if( $res->ParentID == 0 ) {
echo '<ul class="recursive">';
echo '<li>';
echo $res->Name;
echo $res->Description;
echo $res->date_added;
echo '<ul>';
}
if( $res->ParentID != 0 ) {
echo '<li>';
echo $res->Name;
echo $res->Description;
echo $res->date_added;
echo '</li>';
}
$STH = $DBH->query("SELECT * FROM ".$tbl." WHERE ParentID = '".$res->ID."'");
$fquerycount = $STH->rowCount();
$STH->setFetchMode(PDO::FETCH_OBJ);
recursive_array($STH,$tbl);
if( $res->ParentID == 0 ) {
echo '</ul></li></ul>';
}
}
}
}