Getting the total price of all products in the cart

Discussion in 'PHP' started by Kyriakos, May 21, 2008.

  1. #1
    hi,

    i want to get the total price of all products in my cart (the quantity price sum of each product). [​IMG]

    my php code for this field:
    <?php echo sprintf( '%01.2f', $row['pricer'] * $row['qty'] ); ?>
    PHP:

     
    Kyriakos, May 21, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    I'm assuming that you are looping through the results so that you can display each row properly. I would set an array with the total item price and then do an array sum at the end.

    When you are looping do something like this:
    
    
    $totalArray[] = $row['pricer'] * $row['qty'];
    
    
    PHP:
    At the bottom do this:
    
    
    $total_price = array_sum($totalArray);
    
    
    PHP:
    You can then format it to whatever currency or numerical format you need.
     
    jestep, May 21, 2008 IP