行分页时如何检索列总数? [英] How to retrieve column total when rows are paginated?

查看:57
本文介绍了行分页时如何检索列总数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表中有一列价格",并且我使用了分页脚本来生成显示的数据.现在分页工作正常,但是我试图在HTML表中最后一行显示所有价格的总和.所以我写了一个脚本,用一个foreach循环来做到这一点,它的确可以给我总计所有价格的总和,但是它是所有行的总和,即使是后面几行的总和.如何只检索分页中显示的行的总和?

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?

这里是查询.

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";

推荐答案

只需使用MySQL函数 FOUND_ROWS():

Just use MySQL function FOUND_ROWS(): http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_found-rows

这篇关于行分页时如何检索列总数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆