How to retrieve column total when rows are paginated?

Posted by Rick on Stack Overflow See other posts from Stack Overflow or by Rick
Published on 2010-12-25T06:38:59Z Indexed on 2010/12/25 8:54 UTC
Read the original article Hit count: 238

Filed under:
|
|
|

Hey guys I have a column "price" in a table and I used a pagination script to generate the data displayed. Now the pagination is working perfectly however I am trying to have a final row in my HTML table to show the total of all the price. So I wrote a script to do just that with a foreach loop and it sort of works where it does give me the total of all the price summed up together however it is the sum of all the rows, even the ones that are on following pages. How can I retrieve just the sum of the rows displayed within the pagination?

Thank you!

Here is the query..

SELECT purchase_log.id, purchase_log.date_purchased, purchase_log.total_cost, purchase_log.payment_status, cart_contents.product_name, members.first_name, members.last_name, members.email FROM purchase_log LEFT JOIN cart_contents ON purchase_log.id = cart_contents.purchase_id LEFT JOIN members ON purchase_log.member_id = members.id GROUP BY id ORDER BY id DESC LIMIT 0,30";

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql