• ThinkPHP 分页


    话不多说,代码如下:

    1、mysql

    CREATE TABLE `joys_user` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `username` varchar(150) NOT NULL,
      `password` varchar(100) NOT NULL,
      `name` varchar(255) NOT NULL,
      `email` varchar(100) NOT NULL,
      `reg_date` datetime NOT NULL,
      `last_login_date` datetime NOT NULL,
      `active` tinyint(1) NOT NULL,
      `params` text NOT NULL,
      PRIMARY KEY (`id`),
      UNIQUE KEY `username` (`username`),
      UNIQUE KEY `email` (`email`),
      KEY `name` (`name`)
    ) ENGINE=MyISAM AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;
    
    INSERT INTO `joys_user` VALUES ('3', 'admin', '123456', 'administrator', 'aba@qq.com', '0000-00-00 00:00:00', '2015-11-10 09:32:58', '1', '');
    INSERT INTO `joys_user` VALUES ('6', 'u1', 'e10adc3949ba59abbe56e057f20f883e', 'user1', 'user1@120.com', '2015-11-10 09:45:28', '0000-00-00 00:00:00', '1', '');
    INSERT INTO `joys_user` VALUES ('4', 'alex', '123456', 'alexma', 'alex0018@126.com', '0000-00-00 00:00:00', '2015-10-29 17:25:13', '1', '');
    INSERT INTO `joys_user` VALUES ('7', 'u2', '123456', 'user2', 'user2@120.com', '2015-11-10 09:46:46', '0000-00-00 00:00:00', '1', '');
    INSERT INTO `joys_user` VALUES ('8', 'u3', '123456', 'user3', 'user3@120.com', '2015-11-10 09:47:18', '0000-00-00 00:00:00', '1', '');
    INSERT INTO `joys_user` VALUES ('9', 'u4', '123456', 'user4', 'user4@120.com', '2015-11-10 09:47:51', '0000-00-00 00:00:00', '1', '');

    2、模型文件userModel.class.php

    .......

    3、Action控制器代码

    class UserAction extends CommonAction{
        function index(){
            import('ORG.Util.Page');
            $user = new UserModel();
            
            //数据分页
            $count = $user->count();
            $page = new Page($count,5);//C()获取配置文件的设置
            $show = $page->show();
            $this->assign('show',$show);
            
            //根据分页信息提取数据
            $list = $user->order('id')->limit($page->firstRow.','.$page->listRows)->select();
            $this->assign('ulist',$list);
           
            $this->display();    
        }
    }

    4、视图模板文件index.html

    <table border="1" bordercolor="black" width="100%">
    <tr><th>用户名</th><th>昵称</th><th>是否激活</th><th>ID</th></tr>
    <volist name="ulist" id="user">
        <tr>
            <td><a href="__URL__/edit/id/{$user['id']}">{$user['username']}</a></td>
            <td>{$user['name']}</td>
            <td>{$user['active']}</td>
            <td>{$user['id']}</td>
        </tr>
    </volist>
    </table>
    {$show}
    If the copyright belongs to the longfei, please indicate the source!!!
  • 相关阅读:
    括号匹配
    超级阶梯问题
    进制问题
    rwkj 1423
    next_permutation
    rwkj 1420
    uva-10392-因数分解
    uva-10305-水题-拓扑排序
    uva-10194-排序
    uva-10152-乌龟排序
  • 原文地址:https://www.cnblogs.com/longfeiPHP/p/4952035.html
Copyright © 2020-2023  润新知