开发者

PHP/MySQL - Show user the number of results their query had, even if you are limiting the number displayed?

开发者_JS百科

Apologies if I am not wording this correctly but what I have at the moment is a search form and the user can type in how many results they want to be returned but what I would like to do is also show the user the total number of matches in the database.

e.g. User selects their search criteria with a limit of 10 but there are 50 matches in the database.

I would like to tell the user is that there are 50 possible results.

One thing I am not sure of is if this can be combined with my existing query or if a separate query will have to be submitted?

The PHP code to generate my queries is quite complicated but if you would like me to post it just let me know.

Thanks.


Have a look at the SQL_CALC_FOUND_ROWS option for mysql.

http://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function_found-rows

And yes, you'll need a second query like:

SELECT FOUND_ROWS()

To get the "real" number of 'would have been' results.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜