PHP search MySQL Database plus paging browse summary

Source: Internet
Author: User
Tags add time throw exception

PHP Search Plus Page view summary: 1 page after the search 2 here for the concatenation of the URL, as well as fuzzy query, search time display Add, SQL statement splicing 3 for the page passed over the hyperlink variable, if not exist to set, for possible throw exception to add @ Mask error 4 For queries generally use some keywords to get 5 page display of the limit condition to write good 6 when searching for the Where Condition search form:<!---search Form---><form action= "list3.php" method= "Get" > Title: <input type= "text" name= "title" Size= "Ten" value= "<?php Echo @$_get[' title '];? > "/>  keyword: <input type=" text "name=" keywords "size=" ten "value=" <?php echo @$_get[' keywords '];? > "/> <input type=" text "name=" author "size=" Ten "value=" <?php Echo @$_get[' author '];? > "/> <input type=" submit "value=" search "/><input type=" button "value=" All Information "onclick=" window.location= ' list3.php ' "/></form><!----------------> Pagination Package <?php//=======================// Encapsulates the search information//defines an array variable that encapsulates the search condition $wherelist=array ();//defines a URL for the encapsulated search, which is used to place the URL as a parameter $urllist=array ();//Determine if the news headline has a value to encapsulate the search condition if (!empty ($_get[' title ')) {$wherelist []= "title like '%{$_get[' title ']}% '"; $urllist []= "title={$_get[' title ']}";} To determine if the keyword has a value, encapsulate the search condition if (!empty ($_get[' keywords ')) {$WHerelist[]= "keywords like '%{$_get[' keywords ']}% '"; $urllist []= "keywords={$_get[' keywords ']}"; Determine if the author has a value to encapsulate the search condition if (!empty ($_get[' author ')) {$wherelist []=] author like '%{$_get[' author ']}% ' "; $urllist []=] Author ={$_get[' author '} ";} Assemble search conditions//combine arrays into strings with implode (), if (count ($wherelist) >0) {$where = "where". Implode ("and", $wherelist); [ Email protected] "&". Implode ("&", $urllist);} echo @ $where;//echo @ $url;//=======================?>3 paging <?php//===== inserting pagination processing code =====//1 defining a variable for paging $page=isset ($_get[' page ')? $_get[' page ']:1;//current page, default to 1$pagesize=4;//page size $maxrows= "";//maximum number of data bars $maxpages= "";//MAX pages//Get maximum number of data bars @ $sql = "SELECT count (*) from news {$where}"; $res =mysql_query ($sql, $conn); $maxRows =mysql_result ($res, 0,0);// Locate the number of total data that gets from the result set, which is the value in the first cell//3 calculates the maximum number of pages $maxpages=ceil ($maxRows/$pageSize);//To get the maximum pages, 7/3;//4 to determine whether the pages Determines whether the if ($page > $maxPages) {$page = $maxPages;//Determines whether the maximum page}if ($page <1) {$page = 1;} is exceeded. Stitching $sql, limiting the number of bars displayed per page $limit= "Limit". (($page-1) * $pageSize). ", {$pageSize}";//The starting position is the current page minus 1 times the number of bars displayed per page//========== page Wrap End ==============@ $sql = "SELECT * from news {$where} ORDER by addtime desc {$limit}";//limit 0,3 means from the first record to the third record// Show the latest news First [Email protected]_query ($sql, $conn); > Specific examples: News search and Paging program: Search and Paging functions as follows: list3.php full code <?phpheader ("Content-type:text/html;charset=utf-8"); ><?phprequire ("menu.php"); Require ("dbconfig.php");? ><title> News Information Management system </title><script>function Dodel (ID) {//Determine if you want to remove the if (Confirm ("OK to delete? ") {window.location=" action.php?action=del&id= "+id;}} </script><center>
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.