Pagination display is a way to browse large amounts of data. For beginners often do not have a clue to this issue, so specially write this article on this issue for detailed explanation, and strive to let the reading of this article after reading the principle of pagination and the realization of the method to understand.
All sample code is written using PHP.
The so-called paging display, that is, the result set in the database for the artificial division into a paragraph to display.
Please read the following code in detail, debug your own run once, it is best to modify it once, plus its own functions.
$wherelist =array ();
$urlist =array (); if (!empty ($_get[' title ')) {$wherelist []=] title like '% '. $_get[' title ']. "
%'";
$urllist []= "title=". $_get[' title ']; } if (!empty ($_get[' keywords ')) {$wherelist []= ' keywords like '% '. $_get[' keywords ']. "
%'";
$urllist []= "keywords=". $_get[' keywords ']; }if (!empty ($_get[' author ')) {$wherelist []= ' author like '% '. $_get[' author ']. "
%'";
$urllist []= "author=". $_get[' author '];
} $where = "";
if (count ($wherelist) >0) {$where = "where" implode (' and ', $wherelist);
$url = ' & '. Implode (' & ', $urllist);
///pagination implementation principle//1. Gets the total number of records in the datasheet $sql = "SELECT count (*) from news $where";
$result =mysql_query ($sql);
$totalnum =mysql_num_rows ($result);
Show number of bars per page $pagesize = 5;
A total of several pages $maxpage =ceil ($totalnum/$pagesize);
$page =isset ($_get[' page ')? $_get[' page ']:1; if ($page <1) {$page =1} if ($page > $maxpage) {$page = $maxpage;} $limit = "Limit".
($page-1) * $pagesize. ", $pagesize";
$sql 1= "SELECT * from news {$where} {$limit}";
$sql 1= "SELECT * from news {$where} {$limit}"; $rEs=mysql_query ($sql 1); ?> <form action= "searchpage.php" method= "get" > title: <input type= "text" name= "title" Value= "<?php Echo $_ get[' title ']?> ' size= "8" > Keyword <input type= "text" name= "keywords" value= "<?php echo $_get[' keywords ']?> '" Size= "8" > Author: <input type= "text" name= "author" value= "<?php echo $_get[" author ']?> "size=" 8 "> <input
Type= "button" value= "View All" onclick= "window.location= ' searchpage.php '" > <input type= "Submit" value= "Search" > </form> <table border= "1" width= "1000" align= "center" > <tr> <td> number </td> <td> title ;/td> <td> keywords </td> <td> author </td> <td> date </td> <td> content </td> </tr&
Gt
<?php while ($row = Mysql_fetch_assoc ($res)) {?> <tr> <td><?php echo $row [' ID ']?></td> <td><?php echo $row [' title ']?></td> <td><?php echo $row [' keywords ']?></td> < td><?php echo $row ['Author ']?></td> <td><?php echo Date ("Y-m-d h:i:s", $row [' Addtime '])?></td> <td>< ? php echo $row [' content ']?></td> </tr> <?php}?> <tr> <td colspan= "6" > <?php Echo
"Current {$page}/{$maxpage} page altogether {$totalnum}]";
echo "<a href= ' searchpage.php?page=1{$url} ' > Home </a>"; echo "<a href= ' searchpage.php?page=". ($page-1). "
{$url} ' > Prev </a> '; echo "<a href= ' searchpage.php?page=". ($page + 1). "
{$url} ' > next page </a> ';
echo "<a href= ' searchpage.php?page={$maxpage} {$url} ' > Last </a>"; ?> </td> </tr> </table>
I hope this article will help you with your PHP programming.