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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.