Use PHP to access database _ to implement the paging function and multi-condition query function example, access data Paging

Source: Internet
Author: User

Use PHP to access database _ to implement the paging function and multi-condition query function example, access data Paging

1. Implement Paging

<Body> <table width = "100%" border = "1"> <thead> <tr> <th> Code </th> <th> name </th> <th>> price </th> </tr> </thead> <tbody> <? Php require_once ". /DBDA. class. php "; // load the database metadata class package file require_once" page. class. php "; // load the encapsulated file of the paging class $ db = new DBDA (); $ SQL =" select count (*) from car "; $ arr = $ db-> query ($ szts); $ page = new Page ($ arr [0] [0], 5); // view the total data, and the row data displayed on each page $ SQL = "select * from car ". $ page-> limit; // splice the data displayed on each page $ arr = $ db-> query ($ SQL); foreach ($ arr as $ v) {echo "<tr> <td >{$ v [0] }</td> <td >{$ v [1] }</td> <td >{$ v [2] }</td> </tr> ";}?> </Tbody> </table> <div style = "margin-top: 20px"> <? Php echo $ page-> fpage (); // call the paging class method?> </Div> </body>

2. Multi-condition Query

<Body> <? Phprequire_once ". /DBDA. class. php "; require_once" page. class. php "; $ db = new DBDA (); // create a uniform condition $ tj =" 1 = 1 "; $ tj2 =" 1 = 1 "; $ name = ""; $ brand = ""; // when the submitted data is not empty, you need to change the condition if (! Empty ($ _ GET ["name"]) {$ name = $ _ GET ["name"]; $ tj = "name like '% {$ name} %'"; // use fuzzy search to query key information} if (! Empty ($ _ GET ["brand"]) {$ brand =$ _ GET ["brand"]; $ tj2 = "brand = '{$ brand}'" ;}?> <Table width = "100%" border = "1"> <form action = "test. php "method =" get "> <input type =" text "name =" name "placeholder =" Enter the name "value =" <? Php echo $ name?> "Style =" max-width: 200px; float: left "> <input type =" text "name =" brand "placeholder =" Please input series "value =" <? Php echo $ brand?> "Style =" max-width: 200px; float: left "> <button type =" submit "style =" float: left; margin-left: 10px "> query </button> </form> <thead> <tr> <th> Code </th> <th> name </th> <th> series </ th> <th> time </th> <th> price </th> </tr> </thead> <tbody> <? Php $ zts = "select count (*) from car where {$ tj} and {$ tj2 }"; // total number of multi-condition query data $ ats = $ db-> query ($ arr); $ page = new Page ($ ats [0] [0], 2 ); $ SQL = "select * from car where {$ tj} and {$ tj2 }". $ page-> limit; $ arr = $ db-> query ($ SQL); foreach ($ arr as $ v) {// Add the font color $ n = str_replace ($ name, "<span style = 'color: red' >{$ name} </span> ", $ v [1]); echo "<tr> <td >{$ v [0] }</td> <td >{$ n }</td> <td >{$ v [2]} </td> <td >{$ v [3]} </ Td> <td >{$ v [7] }</td> </tr> ";}?> </Tbody> </table> <div> <? Phpecho $ page-> fpage () ;?> </Div> </body>

The above example of using PHP to access database _ to implement the paging function and multi-condition query function is all the content that I shared with you. I hope to give you a reference, we also hope that you can support the customer's home.

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.