My database structure like ..
user table
| userid | parentid |
| -------- --| ---------------- |
| 343932 | 112333 |
| 386383 | 343932 |
| 673443 | 386383 |
| 398933 | 673443 |
| 687330 | 673443 |
user Balance table
| user | balance |
| -------- --| ---------------- |
| 112333 | 399 |
| 343932 | 900 |
| 386383 | 800 |
| 673443 | 9000 |
| 398933 | 6000 |
| 687330 | 499 |
condition is if parent has balance user can do transaction. for example user(398933) wants to do transaction of $100 but it parent(673443) has balance but user(673443)'s parent 386383 has no sufficient balance. if user ultimate parent has sufficient balance .. transaction will be succeeded. is there any way to join technicities to get every parents balance in a single queries so program can decide when to discard request.
if any PHP technique, pls advise