i’ve been working on this mlm (pyramid) project, I am done with all the visual pyramid system display etc. now I need to update all parent records of the client. here’s my database table and binary tree of users :

As you can see i have id and parentid, now when i add new user under an id. i need to update all parents’ left / right and commission. I am finding it very complicated.. cos I can’t just update 1 row.. i need to update all its parent rows, may be doing loop or w.e. If anyone has done this before please help me how can i do this.
There are a few methods to maintain hierarchical data on a conventional DBMS such as MySQL. Adjacency List Model, Path Enumeration Model and Nested Set Model are some of them. I sugest reading Joe Celko’s Trees and hierarchies in SQL for smarties. There are also some good articles about managing hierarchical data in MySQL: