Posted: Wed Mar 14, 2007 4:08 pm
Yeah, it's ok to leave such gaps.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
require 'includes/php/db_connect.php';
function get_upline_array($root)
{
//return value
$ret = array();
// retrieve the left and right value of the $root node
$result = mysql_query('SELECT `left_boundary`, `right_boundary` FROM `downline` WHERE `username` = "'.$root.'";') or die(mysql_error());
$row = mysql_fetch_array($result);
// start with an empty $left stack
$left = array();
// now, retrieve all ascendants of the $root node
$result = mysql_query('SELECT `username`, `left_boundary`, `right_boundary` FROM `downline` WHERE `left_boundary` < '.$row['right_boundary'].' AND `right_boundary` > '.$row['right_boundary'].' GROUP BY `username` ORDER BY `left_boundary` DESC LIMIT 0,10;') or die(mysql_error());
// display each row
while($row = mysql_fetch_assoc($result))
{
// only check stack if there is one
if(count($left)>0)
{
// check if we should remove a node from the stack
while($left[count($left)-1] < $row['left_boundary'])
{
array_pop($left);
}
}
// display indented node title
if($row['username'] != $root)
{
$ret[] = $row['username'];
}
// add this node to the stack
$left[] = $row['left_boundary'];
}
return $ret;
}
echo '<pre>';
print_r(get_upline_array('scott'));
echo '</pre>';
?>Code: Select all
Array
(
[0] => jack
[1] => jim
[2] => scrotaye
)