MySQL database encapsulation and paging query, mysql database Paging
<? Php
// My database name is house
Class DBDA
{Public $ host = "localhost ";
Public $ uid = "root ";
Public $ pwd = "root ";
Public $ dbname = "house ";
Public function Query ($ SQL, $ type = 1)
// Two parameters. The second parameter indicates the default value.
{
$ Db = new mysqli ($ this-> host, $ this-> uid, $ this-> pwd, $ this-> dbname );
$ Result = $ db-> query ($ SQL );
If ($ type = "1 ")
// Define query for type 1 and add, delete, modify, and Other Types
{
Return $ result-> fetch_all ();
}
Elsystemic
{
Return $ result;
}
}
}
?>
<Table width = "100%" border = "1" cellpadding = "0" cellspacing = "0">
<Tr>
<Td> Region Code </td>
<Td> region name </td>
<Td> parent Code </td>
</Tr>
<? Php
Include ("DBDA. class. php ");
$ Db = new DBDA (); // call the encapsulated Database
Include ("page. class. php ");
// Check the total number of items
$ Sz = "select count (*) from chinastates ";
$ Az = $ db-> Query ($ sz );
// 1. Create object
$ Page = new Page ($ az [0] [0], 10 );
// 2. concatenate the limit variable of the paging class behind the SQL statement
$ SQL = "select * from chinastates". $ page-> limit;
$ Arr = $ db-> Query ($ SQL );
Foreach ($ arr as $ v)
{
Echo "<tr>
<Td >{$ v [0]} </td>
<Td >{$ v [1]} </td>
<Td >{$ v [2]} </td>
</Tr> ";
}
?>
</Table>
<? Php
// 3. Output paging information
Echo $ page-> fpage (); // Add 0, 1, 2, 3, 4, 5, 6, and 7 as needed in the brackets () to show what can be found in the referenced tool table
// Input from 0 to 7 as needed. For example, echo $ page-> fpage (, 6); only the page on the previous page is displayed.