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.