码迷,mamicode.com
首页 > Web开发 > 详细

ThinkPHP 分页

时间:2015-11-10 10:43:46      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

话不多说,代码如下:

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}

 

ThinkPHP 分页

标签:

原文地址:http://www.cnblogs.com/longfeiPHP/p/4952035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!