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'>
        <td width='30%'>$svreg</td>
        <td width='30%'>$currency $service_price</td>
        <td width='30%'>$receipt</td>

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

thanks dom246

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.