Posts: 1,832
Location: Somewhere else entirely
|
If the tree had a fixed number of levels you might think about redesigning the database, but it sounds like the agents can refer to each other endlessly. There's going to be no way to get all the info you want in one query since there's no way of knowing how many levels you want.
When dealing with trees it is often a good idea to write a recursive function to do all the work for you, along the lines of:
PHP Code:
function print_branch($level, $code) { $result = mysql_query("select * from table where sponsor_code = '$code'"); while($row = mysql_fetch_array($result)) { for($i = 0; $i < $level; $i++) echo "-"; echo $row['Name']; print_branch($level+1, $row['sponsor_code']); } }
function print_tree($code) { $result = mysql_query("select Name from table where code = '$code'"); print_branch(0,$code); }
print_tree('H1122');
It causes a lot of SQL queries but it does the job.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Please login or register to view this content. Registration is FREE (aka MSN handwriting for forums)
|