使用offset + limit查找mySQL查询中的结果总数

问题描述:

我使用Codeigniter做一个分页功能,但我认为这一般适用于PHP / mySQL编码。

I'm doing a pagination feature using Codeigniter but I think this applies to PHP/mySQL coding in general.

我使用offset和limit取回目录列表关于我想要每页的结果。但是,要知道所需的总页数,我需要知道(总结果数)/(限制)。现在我想到第二次运行SQL查询,然后计算所需的行数,但不使用LIMIT。但我认为这似乎是浪费计算资源。

I am retrieving directory listings using offset and limit depending on how many results I want per page. However to know the total number of pages required, I need to know (total number of results)/(limit). Right now I am thinking of running the SQL query a second time then count the number of rows required but without using LIMIT. But I think this seems to be a waste of computational resources.

有什么更好的方法吗?谢谢!

Are there any better ways? Thanks!

编辑:我的SQL查询也使用WHERE选择具有特定category_id的所有行

My SQL query uses WHERE as well to select all rows with a particular 'category_id'