MySQL database encapsulation and paging query, mysql database Paging

Source: Internet
Author: User

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.

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.