Implementation of PHP search plus page Instance analysis

Source: Internet
Author: User
Tags echo date
This article to implement the PHP search plus paging, to solve a large number of paging problem, and strive to let the friends after reading this article on the page display of the principle and implementation of the method have some understanding.

Pagination display is a way to browse large amounts of data. For beginners often do not have a clue to this problem, so specially wrote this article on this issue to explain in detail, and strive to let the friends after reading this post for the page display of the principle and implementation of the method have some understanding.

All sample code is written using PHP.

The so-called paging display, that is, the result set in the database is artificially divided into a section of the display.

Please read the following code in detail, run your own debugging once, it is best to change it once, plus your own features.

$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);} The realization principle of paging is//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)///page display $pagesize=5;//total number of 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= "align=" "Center" > <tr> <td> number </td> <td> title </td> <td> keyword </td > <td> author </td> <td> date </td> <td> content </td> </tr><?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 total {$totalnum} bar"; echo "<a href= ' searchpage.php ? page=1{$url} ' > Home </a> '; Echo ' <a href= ' searchpage.php?page= '. ($page-1). " {$url} ' > Previous </a> ', Echo ' <a href= ' searchpage.php?page= '. ($page + 1). " {$url} ' > Next </a> ', Echo ' <a href= ' searchpage.php?page={$maxpage} {$url} ' > Last </a> ';? ></td > </tr></table>

Summary: The above is the entire content of this article, I hope to be able to help you learn.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.