Date: 01/07/08 (PHP Community) Keywords: html I have a script that calls to itself, though it's initiated from a parent script. Each subsequent child record is indented x spaces for visual representation, but I'm having trouble resetting the value of the counter at certain points. Example:
//Get all top-level (parent) records here
while ($row = $d->dbFetchObject($result)) {
..... html output here....
$oddRow = ($oddRow) ? 0 : 1;
if (db::hasChildren($row->id)) {
createMenuHierarchyTable($row->id);
$oddRow = ($oddRow) ? 0 : 1;
}
}
function createMenuHierarchyTable( $pid, $depth = 1) {
global $d, $oddRow;
...execute query here to get children...
while ($row = $d->dbFetchObject($result)) { ?>
echo str_repeat(" ", $depth) . 'L ' . $row->menu_item_title;
$oddRow = ($oddRow) ? 0 : 1;
if (db::hasChildren($row->id)) {
$depth += 1;
createMenuHierarchyTable($row->id, $depth);
$oddRow = ($oddRow) ? 0 : 1;
} else
$depth--;
}
}
}
I'm not sure how to subtract from the $depth variable otherwise. It resets correctly by Subrecord 3.
|