Tables-Databse

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

Tables-Databse

Post 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
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post 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.
Post Reply