Page 1 of 1

Tables-Databse

Posted: Thu May 13, 2004 2:22 pm
by Kingo
I would really appreciate if any one could help me out.

I want to display the contents of the table from a database with 10 rows per page. The sam ethingh that this forum is displayed. In the End I should get the Page numbers as 1, 2,3...10 . And I I click the page number , i should be able to go that corresponding page. Any help is really appreciated

Posted: Fri May 14, 2004 7:04 am
by kettle_drum
Ok first you need to check the GET or POST values to work out what page number you on:

Code: Select all

if(isset($_GET['p'];)){
      $page = $_GET['p'];
   }else{
      $page = 1;
   }
Then you need a variable to hold the number of entries you want to show per page:

Code: Select all

$num_per_page = 10;
Then work out how many rows of data have been shown before:

Code: Select all

$num_shown = ($page-1)*$num_per_page;
This will result in 0 for the first page, 10 for the second etc.

Now when you call the data from the database add to the end 'LIMIT $numper_page, $num_shown'

This will return 10 rows, starting from the $num_shown value.

Then to get page numbers at the bottom/top of the page, divide the number of result you have by the max number you show on each page and then do a for loop to print the page numbers.