title: Count Multi-level marketing (tree) record in php mysql
body: <p>users table</p>
  
  <p><img src="https://i.stack.imgur.com/BaM5p.gif" alt="enter image description here"></p>
  
  <p>In the Registration time every user have to put parent_id , who registration under parent_id, so i made different table for it</p>
  
  <p>sponser table</p>
  
  <p><img src="https://i.stack.imgur.com/dn8IB.gif" alt="enter image description here"> </p>
  
  <p>after that make tree like that</p>
  
  <p><img src="https://i.stack.imgur.com/p4XdG.gif" alt="enter image description here"></p>
  
  <p>and i want to count record like that</p>
  
  <p><img src="https://i.stack.imgur.com/e5Rjw.gif" alt="enter image description here"></p>
  
  <p>so plz guide me how can i count record like that or there is any way i mean to say for this kind of counting i have to change in database , thanks in advance</p>