Yes! Thanks Rob. I replaced the 'while' content with a printf command and the results were correct.
As you so quickly fixed the problem, i'll put up the function here, in case it is of any use to others looking to parse a tree breadth-first. The function returns an array of ID numbers, separated by *'s, which can then be used by other functions to display the tree structure or perform other calculations on the data. Any suggestions on how to improve the function would of course be much appreciated, i'm by no means an experienced coder.
The table is called dists, and contains a key ID, and a sponsor field (the ID of the person who introduced this person).
Thanks,
Don
<?php
function queue_add($root)
{
$queue = array();
// add root to first place in queue
array_splice($queue, 0, 0, $root);
$store = array();
//wheever your connect details are
include("connect.inc");
while ($queue[0] != null)
{
//get node from front of queue
$current = $queue[0];
// get children of current node
$result = mysql_query("SELECT id FROM dists WHERE sponsor=$current", $db);
// add children to the end of the queue
while ($row=mysql_fetch_array($result)) {
$queue[]=$row["id"];
$store[]=$row["id"];
}
//remove the first item in queue
array_splice($queue, 0, 1);
// add the 'end of level' separator character to $store
array_splice($store, count ($store), 0, '*');
echo "Loop! <br>";
} //end while
return $store;
} // end function
?>