increment referrers level by 1

Discussion in 'PHP' started by alimoses, Sep 28, 2010.

  1. #1
    How do handle this?
    A system that allow people to register and introduce others to register too.
    The entry level is 1,
    For instance, if u introduce Mr. A, ur level increase by 1, if mr A introduce B, ur level increase by 1, Mr. A's level increase by 1

    bt d problem now is hw to increment d level of d other referrer. say D was introduced by C who ws introduced by B who was introduced by A. So the level of A, B, C has to increment by 1. which means by d time D is registered , A level=4, B level=3, C level=2
     
    Last edited: Sep 28, 2010
    alimoses, Sep 28, 2010 IP
  2. bartolay13

    bartolay13 Active Member

    Messages:
    735
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    98
    #2
    can you elaborate more on this. and technically
     
    bartolay13, Sep 28, 2010 IP
  3. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #3
    You might want to look into doing this as a binary tree; You will need to apply some logic on the tree depth as the person at the top will be depth 0 (and wont actually increment).

    However, people that are referred will be added to a new level below the person that referred them so you can simply count the maximum depth below that person to get their level - simples.

    This will automatically grow to any size, so you might also want to consider if you need to use a maximum leve lnumber.


    (It is also the more efficient way to store relationships such as this)

    More infotmation on trees here;

    http://www.simple-talk.com/sql/t-sql-programming/binary-trees-in-sql/
     
    lukeg32, Sep 28, 2010 IP