What is Pagination?
Think about if you have a mysql table with a thousand rows, and you want to allow the user to browse through the entire table. Displaying all the records in that table in one page would not be a good idea. Instead you should break the table up into smaller parts and let the user navigate through it. This is what pagination is, it allows you to break up large results from a database query, and displays a better navigation for the users.
The following code is a quick and dirty example of php/mysql pagination but if you are familiar with CSS, you can easily style the way the page navigation looks.
if(!empty($_GET["start"])){
$start = $_GET['start'];// To take care global variable if OFF
}else{
$start = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$limit = 5; // No of records to be shown per page.
$whathis = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// to check the total number of records
$query = mysql_query(" SELECT * FROM " ) or die (mysql_error());
$total_rows = mysql_num_rows($query);
//select the record with limitation
$query = mysql_query(" SELECT * FROM limit $eu, $limit " ) or die (mysql_error());
//code for previous
if($back >=0) {
echo "PREV ";
}
Think about if you have a mysql table with a thousand rows, and you want to allow the user to browse through the entire table. Displaying all the records in that table in one page would not be a good idea. Instead you should break the table up into smaller parts and let the user navigate through it. This is what pagination is, it allows you to break up large results from a database query, and displays a better navigation for the users.
The following code is a quick and dirty example of php/mysql pagination but if you are familiar with CSS, you can easily style the way the page navigation looks.
if(!empty($_GET["start"])){
$start = $_GET['start'];// To take care global variable if OFF
}else{
$start = 0;
}
if(!($start > 0)) { // This variable is set to zero for the first page
$start = 0;
}
$eu = ($start - 0);
$limit = 5; // No of records to be shown per page.
$whathis = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
// to check the total number of records
$query = mysql_query(" SELECT * FROM
$total_rows = mysql_num_rows($query);
//select the record with limitation
$query = mysql_query(" SELECT * FROM
//code for previous
if($back >=0) {
echo "PREV ";
}
No comments:
Post a Comment