Hey, im writting a little piece of code which queries a departments table in my database looking for an IDs children nodes and then displays them. While doing this it looks for the childrens children and so on. this should create a family tree like page showing the hyarachee of departments, to do this i have done something like this:
#main page
DeptID = top of the tree;
include the dept information file;
#end of main page
#dept information file
find DeptID's children;
for each of the children:
Increase VariableArrayID by one
deptID = children ID;
include the dept information file
end for;
revert VariableArrayID back to original VariableArrayID
[/B]
you see it keeps including the same file for each of the parents children.
now a technicality i foudn was that i was reusing the same variables which i thought might be stopping it from working so i introduced an array of the variables and i recert back to the originals after the children has been executed.
but havning just typed that im wondering if the old_VariableArrayID needs to be arrayed too?!? argghhh this is complex! hehehe
right now what its doing is going down one path of the tree and when it recverts back to the original ID the while loop doesnt seem to work 🙁
humn, well heres the code anyway, id really appreachiate any help with this as i spent all yesterday on it and i will proberly spend all day on it again! 🙁
thanks
<?php
#requires $dept_ID
$result2 = mysql_query("SELECT * FROM global_dept WHERE dept_ID='$dept_ID[$i]'");
$row2 = mysql_fetch_array($result2);
$node_name = $row2["dept_name"];
$result = mysql_query("SELECT * FROM global_dept WHERE dept_parent='$dept_ID[$i]'");
$childrencount[$i] = mysql_num_rows($result);
?>
<table width="500" border="1" align="center" cellpadding="3" cellspacing="0" bordercolor="#CCCCCC">
<tr><td colspan="<?=$childrencount[i]?>" valign="top"><div align="center"><strong>
<a href="#">Supervisors</a><br>|</strong></div></td></tr><tr bgcolor="#CCCCCC">
<td colspan="<?=$childrencount[$i]?>" valign="top"><div align="center">
<h3><strong>Department : <?=$node_name?></strong></h3>
<h5 align="left"><strong>current value of i: <?=$i?></strong></h5>
<h5 align="left"><strong>Supervisors: [put_name_here]<br>
Immidiate staff: <?=$childrencount[$i]?>
<br>Containging departments: <?=$childrencount[$i]?>
</strong></h5><h3 align="center"><strong><br>
<input type="submit" name="Submit3" value="Add new Dept" class="button">
<input type="submit" name="Submit332325" value="Add new staff" class="button">
</strong></h3></div></td></tr>
<?php
if ($childrencount[$i] > 0 ) {
$percentage = 100 / $childrencount[$i];
?><tr>
<?php
echo '<tr ><td colspan="<?=$childrencount[$i]?>">changing ' . $i . ' to ' . ($i + 1) . '</td></tr>';
$old_i = $i;
$i++;
if ( $i >100) {
echo 'error';
exit;
}
while ( $row[$old_i] = mysql_fetch_array($result) ) { #---------------------
?><td valign="top" width="<?=$percentage?>%"><div align="center">
<?php
$dept_ID[$i] = $row[$old_i]["dept_ID"];
include("global/dept_tree.php"); ?>
</div></td>
<?php
} #--------------------
echo '<tr ><td colspan="<?=$childrencount[$i]?>">reverted back to ' . $old_i . ' from ' . $i . '</td></tr>';
$i = $old_i; ?>
</tr>
<?php
} else { echo'<tr ><td colspan="<?=$childrencount[$i]?>">Im an end node</td></tr>'; } ?>
</table>