thinkphp Paging Implementation

Source: Internet
Author: User

Note: To first configure the following code in the configuration file:

<?PHPreturn Array(    //' Config item ' = ' config value '     /*Database Settings*/' App_debug ' =true, ' show_page_trace ' =true, ' db_type ' = ' mysql ',//Database Type' db_host ' = ' localhost ',//Server Address' Db_name ' = ' 7799520 ',//Database name' Db_user ' = ' root ',//User name' Db_pwd ' = ' 222222 ',//Password' Db_port ' = ' 3306 ',//Port' Db_prefix ' = ',//database table Prefixes' Db_fieldtype_check ' =false,//whether field type checking is done' Db_fields_cache ' =true,//Enable field caching' Db_charset ' = ' UTF8 ',//database encoding is UTF8 by default' Db_deploy_type ' = 0,//Database Deployment method: 0 Centralized (single server), 1 distributed (Master-slave server)' Db_rw_separate ' =false,//whether the database reads and writes separate master-slave valid' Db_master_num ' = 1,//number of master servers for read-write separation' Db_sql_build_cache ' =false,//SQL Create cache for database queries' Db_sql_build_queue ' = ' file ',//SQL cache queues are cached to support file XCache and APC' Db_sql_build_length ' = 20,//Queue Length for SQL cache' Var_page ' = ' P ',//paging parameter, this must be configured);?>

First implement this code in the controller:

<?PHP//This class is automatically generated by the system and is intended for testing purposes onlyclassIndexactionextendsAction { Public functionindex () {$moden=m (' Customers '); /*page Out*/Import ("ORG. Util.page ");//Import page-out class        $count=$moden-Count();//the total number of records that the query meets the requirements        $Page=NewPage ($count, 15);//instantiate the number of incoming total records in a paging class and the number of records displayed per page        $show=$Page->show ();//pagination Display Output        $rs=$moden->field ("Id,account,qq,sex_id,nick")->limit ($Page->firstrow. ', '.$Page->listrows)Select (); $this->assign (' page ',$show);//Assignment Paging output        /*End of Page*/        $this->assign (' list ',$rs); $this-display (); }}

It is then called in the template, and the code in the specific template is as follows:

<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metahttp-equiv= "X-ua-compatible"content= "Ie=edge,chrome=1"><title>Examples</title><Metaname= "description"content=""><Metaname= "keywords"content=""><Linkhref=""rel= "stylesheet"></Head><Body>    <TableAlign= "Center"width= "$"Border= "1">            <TR>                    <TD>Id</TD>                    <TD>Account</TD>                    <TD>Qq</TD>                    <TD>Gender</TD>                    <TD>Name</TD>            </TR>        <foreachname= "List"Item= "Vo">            <TR>                <TD>{$vo. ID}</TD>                <TD>{$vo. Account}</TD>                <TD>{$vo. QQ}</TD>                <TD>{$vo. sex_id}</TD>                <TD>{$vo. Nick}</TD>                        </TR>        </foreach>    </Table>    <Div>{$page}</Div></Body></HTML>

The effect is as follows:

thinkphp Paging Implementation

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.