How to sum

Hi can i ask some help how can i sum the amount and group by manufacturer

and i want only to sum if the order_id is equal to 0001
if i have this tables

product_group


    prod_code        productname           manufacturer                   manuf_code

    A001                       laptop                 samsung                         001
    B002                      mouse                  Neo                                005
    A002                      monitor(LED)         samsung                          001
    B001                      keyboard              hp                                  003

orderdetail


  order_id        ord_prodcode           ord_desc                         invqty            price           amount
   0001            A001                      laptop                                5                   100             500
   0001            B002                      mouse                               2                      50            100
  0001             A002                      monitor(LED)                      5                   250             1250
  0004            B001                      keyboard                             5                  25                125


orderheader


   orderdate            order_id
   10-12-13            0001
    10-12-13           0001
   10-12-13            0001
   9-12-13             0001


I dont have idea on how to do this in php,I hope you can help me thank you in advance.

Simple. You dont do it in PHP.

You do it in your query instead.

GROUP BY orderdetail.order_id,product_group.manufacturer

like that


select g.manufacturer, SUM(d.amount) as total
from orderdetail d
inner join product_group g
on d.ord_prodcode=g.prod_code
where d.order_id='0001'
group by g.manufacturer

@ StarLion,@gk53, Thank you for the reply but i tried to display the data but it did not work when i query this in wampserver it shows the data…i am confuse why it did not display


$sql=mysql_query("select g.manufacturer, SUM(d.amount) as total
from orderdetail d
inner join product_group g
on d.ord_prodcode=g.prod_code
where d.order_id='0001'
group by g.manufacturer");

while($row =  mysql_fetch_array($sql)){
   
          echo "<td>row['amount']</td>
          echo <td>row['manufacturer']</td>";

}



the column name not row[‘amount’] it should be row[‘total’]

HI,it’s working ,thank you so much for helping me.