Jump to content

How to do php pages?


dwex

Recommended Posts

It's called pagination.

 

MySQL has 2 convenient "tools": SQL_CALC_FOUND_ROWS and found_rows() for use with pagination.

 

SELECT SQL_CALC_FOUND_ROWS ..
FROM ..
WHERE ..
LIMIT $offset, $count

 

SQL_CALC_FOUND_ROWS hints MySQL to keep a total of all rows in the result set to be retrieved with found_rows().

 

SELECT found_rows()

 

Returns the total rows in the result set as if the query was executed without the LIMIT-clause. This query has to be followed directly after SQL_CALC_FOUND_ROWS.

 

$totalPages = ceil($foundRows / $count);

 

You calculate the offset from the page number using the below formula:

 

($page - 1) * $count

 

Where $page >= 1 and $count > 0

Link to comment
https://forums.phpfreaks.com/topic/225383-how-to-do-php-pages/#findComment-1163908
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.