title: Trial Balance Update accounts
body: <p>Am looking to update my chartofaccount to get an trial balance here what i have in the table of chartofaccount</p>
  
  <pre><code>Id             parent         Debit          Credit
  
  1
  10              1              
  101             10
  1011            101                          30
  101121231       1011          40
  101134121       1011          20
  </code></pre>
  
  <p>i need the table to look like this </p>
  
  <pre><code>Id             parent         Debit          Credit
  
  1                             60             30
  10              1             60             30
  101             10            60             30
  1011            101           60             30
  101121231       1011          40
  101134121       1011          20
  </code></pre>
  
  <p>The idea is that i need to sum the account Id with respect to the parent</p>
  
  <p>here what am using but its just updating 1 record</p>
  
  <pre><code>    $select2="SELECT sum(debit),sum(credit),parent
                      FROM chartofaccount
                      group by parent
                      ORDER BY parent DESC";
      $run2=mysql_query($select2,$con);
      if(!$run2)die("ERROR22".mysql_error());
  
      for($counter=0;$row1=mysql_fetch_array($run2);$counter++){
  
          $parentid=$row1[2];
          $update3="UPDATE chartofaccount
                      SET debit='$row1[0]',
                          credit='$row1[1]'
                          WHERE Id='$parentid'";
          $run3=mysql_query($update3,$con);
          if(!$run3)die("ERROR1".mysql_error());
  
      }
  </code></pre>