-1

Possible Duplicate:
PHP/MySQL Pagination

I have a website where i am using mysql database. I want to use pagination to view data's in my website. I got lots of pagination script from net but those scripts are not working properly. Now i am trying to make my own simple pagination,can you help me.I dont understand the logic of how pagination works. In some scripts there is a $GET['page'] what is it? .Can you please suggest a simple pagination script also.

Community
  • 1
  • 1
test
  • 1
  • 1
  • 2

4 Answers4

0

Pagination is a problem that can be solved in at least a couple of ways:

  • At the database level
  • At the template level (chunk array etc)

Often the page that should currently be displayed is passed in via GET parameters such as $_GET['page'] like in your example.

To do this at the database level you will be interested in MySQLs LIMIT and OFFSET clauses.

Treffynnon
  • 20,415
  • 5
  • 59
  • 95
0

Pagination isn't something that is included in PHP, so any questions or answers would have to be very specific to your implementation. I would recommend reading some more tutorials and have a couple listed from decent PHP tutorial sites.

OO Based - Yeah!

How to Paginate Data with PHP

Function Based - Boo!

Basic Pagination

Community
  • 1
  • 1
Paul DelRe
  • 3,845
  • 1
  • 21
  • 25
0

$_GET['page'] will refer to a page parameter in the url

e.g. http://www.test.com/mypagination.php?page=1 so here $_GET['page'] = '1'

you can then use that number to determine which results to get and could also use it to build links to previous and next pages

ians
  • 41
  • 1
0

Simply put, pagination works this way:

if you want to show 10 results per page, for a given 'P' page you should get 10 results starting on the (P-1)*10 result. In other words, you should get the first 10 results after the first (P-1)*10 results. This way if you are in page:

1 -> get first 10 after first 0*10 = results from 0 to 10;

2 -> get first 10 after first 1*10 = results from 10 to 20;

3 -> get first 10 after first 2*10 = results from 20 to 30;

...

That $_GET[] is a global variable that allows you to get the parameters passed by GET method. You can also use $_REQUEST[] for the same thing or $_POST[] for input fields of a form.

Luís Sousa
  • 78
  • 1
  • 7