title: Get sum from nodes tree
body: <p>I'm learn php.
  I have this struct </p>
  
  <pre><code>company 1 - $10| all $50
  -company 1.1 - $10| all $20
  --company 1.1.1 - 10$| all $10
  -company 1.2 - $20| all $20
  </code></pre>
  
  <p>each company might have several child-company, and might only one parent. Each company has money.
  All companys have Allmoney - own money + money of all his child companys.</p>
  
  <p>In MySQL this struct like this</p>
  
  <pre><code>id|parent_id|name|money|allmoney
  1| 0| company 1| 10|###
  2| 1| company 1.1|10 |###
  3| 2| company 1.1.1|10 |###
  4| 1| company 1.2|10 |###
  </code></pre>
  
  <p>so, How I calculate allmoney for each company in php? I now, that need using recursion, but I try and nothing can't happen.
  SELECT, UPDATE and other command mysql - I know, Please help me with php.
  I writing something like this:</p>
  
  <pre><code>function updatemoney($id)
      {
          $data = CS50::query("SELECT ...", $id);
          $allmoney = 0;
  
          if(count($data) &gt; 0)
          {
              foreach($data as $row)
              {
  
                  $allmoney += $row["cash"];
                 //somewhere this, maybe need ubdate my db 
                  $allmoney += updatemoney($row["id"]);
              }
          }
          else return 0;
      }
  </code></pre>
  
  <p>Thank you very much</p>