Need Help Finishing a Script; Function To Determine Rank

I probably should have put Numbers or Letters on each circle to help; A Leg is Each Person; downward. So if we start at the Top; with the first Row; you have A - who sponsored B, C, and D. Only C became a Team Leader (TL) - because only C went out and sponsored 5 Team Members (TM’s) - We will call them C1, C2, C3, C4, and C5 for now…

C5 became a Team Director; Because C5 sponsored at least 3 people who sponsored at least 5 TM’s - and became TL’s - Those 3 TL’s pushed C5’s rank to Team Director; But that is all of the production in C5’s Leg; That does not promote C to a higher rank; C5 is a ‘leg’ of C - just as C is a “leg” of A - — B and D are Customers still; but they are also ‘legs’ should they decide to do anything. So the rank is determined by what each person has done Personally; and what their people have done as well.

Personal production, and Team Production - I would need the script to track Each Person as a “Leg” - and determine ranks based on how many Legs that person has; and what those Legs have done. So to our Example - C has 5 legs; C5 has put in a lot of work; But C’s other 4 legs have done nothing at all. If C wants to be promoted, C has to refer more people who are going to be like C5 - if A wants to be promoted, A needs to become a Team Member first; and then A needs 4 more people to also become Team Members - (because C is already One; they need 4 more to qualify)

So just to Clarify - The “YOU” line is A; and on Line 1 - we see B, C, and D. … and the only Production we see on this example is coming from C; and C5 - What C and C5 are doing; is not enough to help out A - with One Exception; C’s “Leg” is a qualified Executive Director Leg; Let’s say for ‘example’ - that B … and D - end up doing the EXACT same thing as C; They Each become Team Members; They Each have One person who becomes a T.D - But has an E.D. pop 4-5 levels down; A … would now have 3 ‘legs’ - with an E.D. in those legs.

However, A (you) still needs to be a 'team member" - in order to Qualify to be Promoted. Everything else would be in place though; A (you) could essentially pay $10; and it would leapfrog them to Regional Director; (because you have 3 ED’s in 3 separate ‘legs’ —

Updated with “Letters”

---- I hope this explains what a Leg is; better than previous attempts!! :slight_smile: (I think Parent/Child is also a good description - Each Child is a Leg; and what each Child does will either Promote the Parent - or not - but that parent also has to meet some qualifications too; 3-5 children; $10 level participation; all of these parts; moving/working together)

*Edit :: some how I missed your response here @StarLion - Need Help Finishing a Script; Function To Determine Rank - #19 by StarLion - between you and @Drummin - you’ve both helped out a great deal; thanks a ton; working on this now (and all week) to see what results come; (Special thanks to @SpacePhoenix as well; as those suggestions are also helpful; I figure once I get this rank script working; I can go back and tidy up the ‘deprecated’ code with the new stuff. one thing at a time - again thanks to all for your help with this;

just want to acknowledge this; I am going to play around with that and see what I get! thanks for this - will test this all out this coming week!

hmmm and yes looking at the second version of the script you attempted; this is very interesting; I think I understand what you are doing; I think the reason it’s not pulling valuable data is the PR_count needs 5 Team Members - or 5 people who’s $ranktng = ‘team member’ - based on the original incomplete script - From what I see, I cannot tell that it’s looking for TM’s - only 5 People - if they have 5 Customers - that wouldn’t push them up; Not sure if that’s the issue; but I like this - I am still going to test it out to see what happens; looking forward to what comes out of those tests; thanks again to everyone who has weighed in; I’ve gotten a lot of value out of this discussion so far.

I know this is old but why not create a table for ranks. Then a table for the conditions of each rank tied to their rank. Evaluate the conditions against the users data. Heck if you know what data you will be evaluating the rank table can store all of that and the you can evaluate that against the users data to assign them their rank. Save you some table joins. Reduce your code to an oop approach for reusabilty and testabilty. I’m on my phone or I show you an example.

1 Like

Yes I agree. This was suggested post #4 but got lost post #6 or so when he went for a daily run instead of when a new person joins or upgrades.

1 Like

Hey; not Old at all; I’ve actually been putting some of what Drummin suggested into application; but also hit the same wall he mentioned in not being able to “drill down” — was not able to incorporate what Star Lion shared as a suggestion to drill down; However - No decision was made not to go with the #4 post suggestion of using a table to store ranks; in fact that’s where I’m at currently; working on figuruing out how to use where I am so far (successfully was able to tie it into reading my Current Table; and how many referrals each user has; It just isn’t able to ‘accurately’ detect the other people’s ranks; and that is where the Table would come in) – but; had not got to that point as of yet. So I look forward to what you were planning to put together; I think everything is very close now.

Yes, kingc. It’s a tricky bit of logic to figure out regardless of when it is run. Do you have a DB table with enough records to do real testing for higher ranks?

1 Like

After you update or insert the data do a check to see if they are able to get a new rank. Compare the rules for the next rank with the users current data and the change the users associated rank if the data matches the rules for the new rank. I see your trying to build a tree data structure but in truth you could do it another way. If your trying to use that as a display use a tier approach instead.

1 Like

When someone joins/upgrades (whatever) you need to not only check if this person’s sponsor has qualified but then their upline, which will include legs not directly in this upline path. So you might be able to check for personal referrals and update the sponsor but updating all upline would be more complicated. It certainly could be done with some nasty looped queries but we’re trying to avoid that.

1 Like

Are the stats stored in the users table or reference tables? I see you have referrals, acquisition goals, and team goals. How is the data structured? Sitepoint does have an article on building a tree with unlimited depth.

Tree data structure

Data storage

One pass tree structure
http://www.tommylacroix.com/2008/09/10/php-design-pattern-building-a-tree/

I was making a skill tree and thought I needed a tree structure but the settled on a row column solution with the skills having a tier for hierarchy and panel for placement. Just a suggestion for the visuals. Trees would need unlimited depth and looping through a huge data set could eat a lot of resources. The method I suggested uses a 2d array and could be populated in the while loop used to normally display the data. You could on a per person basis use a cron that checks and evaluates the data and handles rank increase or do it by a chunk for that person. Grab everyone associated and process it that way.

1 Like

Yes @Drummin - my current DB table has plenty of records; and a handful of people who should be ‘qualified’ for those higher ranks - @animedreamz73 - in a way that sounds like the same thing (tree branch/tier structure) - and so yes that is what I’m seeking to do; if there is an easier more efficient way to do it; that’s what I’d be interested in doing.

I was considering adding a new row to the DB Table; that would store the Rank; and so on sign up; the rank would be set to the default starting position of lead; like my Current ‘rank script’ does so far.

 // determine the Rank!
$ranktng = "lead";
if ($checkfreelevel == "unlocked") { 
$ranktng = "customer";
}
if ($ranktng == "customer" && $checktenlevel == "unlocked") {

$ranktng = "team member";
}
//end of rank

The $checkfreelevel and $checktenlevel are pre-defined variables; that check whether or not each ‘level’ is locked, or unlocked; and what I was thinking is that I would need to modify this code to, Update the DB Table’s rank_row ::: and then I was going to turn my attention to the other part of the script.

The ‘array/code’ you provided @Drummin, I slightly modified;

$peopletng = array('id'=> $row_rankingspage['tngusername'], 'rid' => $row_rankingspage['referbyusername'], 'name' => $row_rankingspage['tngusername']);

I created a new array $peopletng - swapped it out with the other part of the code you shared and it accurately Upgraded the $ranktng variable to Team Leader; on the Records that had 5 referrals, or more. However, it wasn’t accurate (of course - for all the reasons you’ve mentioned already) because the script was not determining whether or not those referrals were leads; customers; or Team Members. I think this is where storing/updating a DB Table, rank_row would make that part easier to do.

As far as updating all upline; I was hoping the same script could be set to Run Once a Night; and automatically check each record; and Update Each Record - based on the Changes (if any) that day. The script would basically be ‘called’ when a person updates their profile; and later that night when the script is called to check records and update the rank_row for each. At least, that is what I’m thinking needs to happen - I think we’re real close to figuring out how to pull it all off.

these look like very good and relevant articles; lol you were answering my question as I was typing it up! :slight_smile:

Awesome. Would creating a new table with the named rank. Here is what I’d do.

Create a table called rank with these fields.

Id int not null auto_increment primary key
title varchar 16
referal_quota int
lead_quota int
performance_quota int
tier int
next_rank id self reference this tables id

That would allow your ranks to be named, and have the required stats to achieve them associated with them. So in your users table you could get the current rank, query the next rank, get the users referals, leads, and performance and test it against the ranks requirements. If they meet change rank, it it excceds it see if they can meet the next rank, if it doesnt meet the first rank do nothing, and if it doesnt meet the second rank but does the first just rank them up once. The tier functions as rows so when its displayed you can add each rank to it’s tier. Tier one would be the highest rank with the highest stats and trickle down. The 2d array can be built during the while loop. Your query would need to order the users accordingly i.e. alphbetical by name. I’m on my phone so I can’t do much code wise.

1 Like