SELECT t1.name AS lev1, t2.name as lev2, t3.name as lev3, t4.name as lev4,t5.name as lev5
FROM members AS t1
LEFT JOIN members AS t2 ON t2.upline_id = t1.member_id
LEFT JOIN members AS t3 ON t3.upline_id = t2.member_id
LEFT JOIN members AS t4 ON t4.upline_id = t3.member_id
LEFT JOIN members AS t5 ON t5.upline_id = t4.member_id
WHERE t1.name = 'B';

hello.. can someone help me.. we're developing some binary multi level marketing
parent child relationship.. the following code can be useful if we only have 2 to 5 levels
we can just left join it.. but my problem is how about if the levels are 50+ ... how can i query that..


First I would try the performance of your attempt with the expected number of participants. MySQL can be quite performant, so maybe there is no need to change your code.
But probably you would be better off with another type of tree organization, the Nested Set Model. Have a look at http://dev.mysql.com/tech-resources/articles/hierarchical-data.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.