Sum of a PHP Array

Posted by user1879415 on Stack Overflow See other posts from Stack Overflow or by user1879415
Published on 2012-12-19T15:02:17Z Indexed on 2012/12/19 17:03 UTC
Read the original article Hit count: 189

Filed under:
|
|

The following code displays the ordered products individual weight:

$weightsql = 'select op.products_name, op.products_quantity , p.products_weight from ' . TABLE_ORDERS_PRODUCTS . ' op left join ' . TABLE_PRODUCTS . ' p on op.products_id = p.products_id where op.products_id =  '.$pro['products_id'];

$weightq = tep_db_query( $weightsql );

while ($weight = tep_db_fetch_array( $weightq )){

        if($category_parent_id != 0)$list_items[] = $weight['products_weight'].'   ';

}

This shows the wieght for each of the products ordered. What I am stuck on is instead of showing seperate weights, I need to show a total weight. For example, if the product was ordered three times, and it weighs 7kg, the code at the moment is showing:

Product                   7.00  7.00  7.00

How would I make it show the total weight, 21kg?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays