php - Parent - Child relationship within a single table
I have a table which is like the following.
parentid uid 10001 10001 10001 10002 10001 10003 10002 10004 10004 10005 10003 10006 10005 10007
I need to establish the parent child relationship between rows in this single table.
I need to get the parent in the reverse order till 4 levels. For example the last record is uid 10007 whose parentid is 10005. Now uid 10005's parent is 10004 and 10004's parent is 10002 and 10002's parent is 10001.
I am using MySQL so recursion seems to be not possible. What are the options that I have and how do I address this multi-level issue. I use PHP/MySQL.
Thanks in advance guys.