0

Am building a vehicle fleet management system, srevice cost is added each time a vehicle is serviced.

Now, lets say vehicle A have been service 8 time, B 5 times, C 10 times ...
I want to show the SUM(cost) for servicing each vehicle at the same time.

I wrote this, but this,but it only select the first service cost of each row like i want it, BUT IT IS NOT SUMING THEM UP

$accra = mysql_query("SELECT  *, SUM(service_price) FROM serv_entry GROUP BY svreg"); 
 while($row = mysql_fetch_assoc($accra)) 
       {
        $id = $row['id'];
        $service_price = $row['service_price'];
        $receipt = $row['receipt'];
        $svreg = $row['svreg'];
        echo "
        <table align='left' class='table table-striped table-bordered'>
        <tbody>
        <tr>
        <td width='30%'>$svreg</td>
        <td width='30%'>$currency $service_price</td>
        <td width='30%'>$receipt</td>
        </tr>
        </tbody>
        </table>
        ";
       } 

Edited by dannybarh: removed unwanted line of code

2
Contributors
2
Replies
11
Views
4 Years
Discussion Span
Last Post by dannybarh
1

In your SQL, try SUM(service_price) as sum_price. Now, in your PHP, try using the field sum_price instead of service_price.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.