so i think i missing something, i trying to use a recuretive funtion but it not working 100%. it goes thru the levels but doesn't stop if there is nothing in the next level. any help would be very helpful?
function display_children($parent, $level){
$dblink = $_SESSION['dblink'];
$sql = "SELECT * FROM `switchboard` WHERE `item_parents` = '".$parent."'";
$result = $dblink->query($sql);
$count = $result->num_rows;
if($count != 0){
while ($row = $result->fetch_assoc()){
if($level == 1){
echo '<h2>' . $row['item_text'] . '</h2>'."\n";
}else{
echo $row['item_parents'] . " | " . $row['item_text'] . '<br />'."\n";
}
display_children($parent+1, $level+1);
}
}
}
database:
item_id item_parents item_number item_text
1 0 0 Admin
2 1 1 Event Facilities
3 1 2 Events
4 1 3 Event/Facilities People
5 1 4 Autocrat Advisors
6 1 5 Atensteward Content
7 1 6 Atensteward Links
8 1 7 Site Users
9 2 1 add
10 2 2 edit
output
0 | Admin<br />
<h2>Event Facilities</h2>
2 | add<br />
2 | edit<br />
<h2>Events</h2>
2 | add<br />
2 | edit<br />
<h2>Event/Facilities People</h2>
2 | add<br />
2 | edit<br />
<h2>Autocrat Advisors</h2>
2 | add<br />
2 | edit<br />
<h2>Atensteward Content</h2>
2 | add<br />
2 | edit<br />
<h2>Atensteward Links</h2>
2 | add<br />
2 | edit<br />
<h2>Site Users</h2>
2 | add<br />
2 | edit<br />