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
Tables-Databse
Moderator: General Moderators
-
kettle_drum
- DevNet Resident
- Posts: 1150
- Joined: Sun Jul 20, 2003 9:25 pm
- Location: West Yorkshire, England
Ok first you need to check the GET or POST values to work out what page number you on:
Then you need a variable to hold the number of entries you want to show per page:
Then work out how many rows of data have been shown before:
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.
Code: Select all
if(isset($_GET['p'];)){
$page = $_GET['p'];
}else{
$page = 1;
}Code: Select all
$num_per_page = 10;Code: Select all
$num_shown = ($page-1)*$num_per_page;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.