Say I have a MySQL table like below. Going from the bottom, I want to find a sponsor that has a "Status = 1". But I want to do it in a order. For e.g. I am "Mike". My sponsor is "Richard". I want to check if "Richard" has a status of 1. He doesn't. So now I am going to check "Richard"'s sponsor to see if he has a status of 1. He doesn't either. So I keep going up, checking my sponsor's sponsor's sponsor...etc.
Normally I can do that with a single or multiple queries if I want to check several levels up. But the problem arises if I want to check infinite levels up until it finds the sponsor who's status is 1? How that work? What would a php query/function look like checking infinite levels up?
Sponsors Referrals Status
--------------------------------------
Zack Joey 1
Joey Tracy 0
Tracy Helen 0
Helen Richard 0
Richard Mike 0
</div>