javascript – How to add the existing rows and remove the previous row-ThrowExceptions

Exception or error:

I want to add the payment. if the payment is for the same contractor, add the payment as grand total and remove the previous row containing payment. I want to compare that is more than one payment exists against the contractor add that payment as grand total remove the previous row regarding payment. And if the contractor payment is a single entity(only one payment against the contractor) fetch from the database no addition will be made and the fetched row is displayed as the grandtotal .Here is my code

  //code to compare that that payment is for thr same contractor whos row is fetched before                

    <?php
    $contractor =0 ; 
    $payment_con=0;

    while($row = mysqli_fetch_array($result))  
    { 
    $price = $row["price"];  
    $total  = $row["CONCAT(Extract(HOUR From timeStamp) ,'.', Extract(MINUTE From timeStamp))"];
    $grandtotal = $total * $price;
    $grandtotal = $grandtotal *0.05; 
    if($contractor == $row['cnic'])  //false
    {
    $payment_con = $payment_con + $grandtotal ;   
    ?>
    <script type="text/javascript">
    function run(){
    document.getElementById('123').style.display='none';
    }
    <?php
    echo "run();";
    ?>
    </script>               
    <tr>  
    <td id="serviceId_<?php echo  $row["mazdoorId"];?>"><?php echo $row["mazdoorId"]; ?></td>  
    <td><?php echo $row["serviceName"]; ?></td>
    <td><?php echo $row["price"]; ?></td>
    <td><?php echo $row["CONCAT(Extract(HOUR From timeStamp) ,'.', Extract(MINUTE From timeStamp))"]; ?></td>
    <td><?php echo $row["contractorName"]; ?></td>
    <td><?php echo $row["cnic"]; ?></td>
    <td><?php echo $grandtotal. "PKR" ?></td>
    <th> GRAND TOTAL  : <?php echo $payment_con. "PKR" ?></th>  <td> <input type="button" name="edit" value="PAID" id="<?php echo $row["customerId"]; ?>" class="btn btn-danger btn-xs deactivate_accounts" /></td>
    </td>  
    </tr>  
    <?php                               
    }
    else
    {
    ?> 
    <tr id= "123">  
    <td id="serviceId_<?php echo  $row["mazdoorId"];?>"><?php echo $row["mazdoorId"]; ?></td>  
    <td><?php echo $row["serviceName"]; ?></td>
    <td><?php echo $row["price"]; ?></td>
    <td><?php echo $row["CONCAT(Extract(HOUR From timeStamp) ,'.', Extract(MINUTE From timeStamp))"]; ?></td>
    <td><?php echo $row["contractorName"]; ?></td>
    <td><?php echo $row["cnic"]; ?></td>
    <td><?php echo $grandtotal. "PKR" ?></td>
    <th> GRAND TOTAL  : <?php echo $grandtotal. "PKR" ?></th>  <td> <input type="button" name="edit" value="PAID" id="<?php echo $row["customerId"]; ?>" class="btn btn-danger btn-xs deactivate_accounts" /></td>
    </td>  
    </tr>  
    <?php
    $contractor = $row['cnic']; 
    $payment_con =$grandtotal ;
    }

    }
    ?>
    </thead>

    </table>
How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *