G'day all,
I have been trying to modify Peter's code for displaying the sections when creating a new section. What I want is for the children of a section to be displayed below the parent with a hyphen in front of the child. Here is my code so far:
PHP Code:
<?php
// Generate a drop-down list of sections, only where section is not a child.
$result = $connector->query('select `sections`.`ID`, `sections`.`name` from sections where (`sections`.`parentid` =0) order by `sections`.`ID` asc');
// Save into array.
$topsect = $connector->fetchArray($result);
// For each, print them check for children.
foreach ($topsect as $top){
echo '<option value="'.$top['ID'].'">'.$top['name'].'</option>';
// Check if above section has children.
$result = $connector->query('select `sections`.`ID` , `sections`.`name` from sections where ( `sections` . `parentid` = '.$top['ID'].' ) order by `sections`.`name` asc');
// If has children print each with a '-' in front.
while($row = $connector->fetchArray($result)){
echo '<option value="'.$row['ID'].'">-'.$row['name'].'</option>';
}
}
?>
At the moment all I get is three lines:
None
1
U
Any ideas?
Thanks in advance,
Marzar