Logic Help
Moderator: General Moderators
That's a great idea.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Sorry for returning to this old topic so many times. I read the article posted in the first response, and took the function in the article and mangled it to display a users UPLINE, up to ten levels up.
This works for the five accounts I have programmed manually into the database. I want to see if it looks right with you devnetters to correctly display up to a 10 level upline, *correctly*, *every time*. I can envision it in my head with only 5 users, but with 5,000 users, I can't begin to picture it. Perhaps some of you more savvy people can tell me if this will work right all the time.
Output:
Which is correct, in order.
This works for the five accounts I have programmed manually into the database. I want to see if it looks right with you devnetters to correctly display up to a 10 level upline, *correctly*, *every time*. I can envision it in my head with only 5 users, but with 5,000 users, I can't begin to picture it. Perhaps some of you more savvy people can tell me if this will work right all the time.
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
)Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.