title: how to count no of left or right child from binary tree database
body: <p>This is a dummy of my table</p>
  
  <p><a href="https://i.stack.imgur.com/DxoqH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DxoqH.png" alt="table"></a></p>
  
  <ul>
  <li>first node is 1</li>
  <li>LorR define child is ini left(0) or Right(1)</li>
  <li>1 st node has two child node 2 and 3 in Left and Right </li>
  <li>2 nd node has two child node 4 and 5 in Left and Right</li>
  <li>3 rd node has two child node 6 and 7 in Left and Right</li>
  <li>4 th node has two child node 8 and 9 in Left and Right</li>
  <li>5 th node has one child node 10 in Left</li>
  <li>6 th node has one child node 11 in Left</li>
  <li>7 th node has one child node 12 in Right</li>
  </ul>
  
  <p>now if i want to find the number of total child nodes of any parent node in each level
  for ex...</p>
  
  <ul>
  <li>node 2 (parent) has a 2 child (4,5) in level 1 &amp; 2 child node (8,9)
  in level 2</li>
  <li>node 6 (parent) has a 1 child (11) in level 1</li>
  <li>node 3 (parent) has a 2 child (6,7) in level 1 &amp; 2 child nodes
  (11,12) in level 2</li>
  </ul>
  
  <p>how can I implement this using php? 
  My code is 
  <a href="https://i.stack.imgur.com/SkW5c.png" rel="nofollow noreferrer">code</a></p>