您好,欢迎访问一九零五行业门户网

qeephp内容分页_PHP教程

当列出查找的内容有很多条的时候我们可以将数据进行分页显示。
user表的结构如图:
现在要将用户以列表的形式显示,显然不可能将查询结果显示在一页当中,此时要将结果分页显示,首先将分页控件page.php复制到项目的control文件中,然后我们可以在控制器中输入如下代码:
01
function actioncuslist()
02
{
03
    $cus_info = user::find();
04
    //获取当前是第几页
05
    $page = intval( $this->_context->page );
06
    $page07
    //设置每页显示的数量
08
    $page_size = 10;
09
10
    //按条件查找用户
11
    if($id = $this->_context->get('cus_id'))
12
        $cus_info->where('id = ?', $id);
13
    else
14
    {
15
        if($first_name = $this->_context->get('first_name'))
16
           $cus_info->where('first_name = ?', $first_name);
17
18
        if($last_name = $this->_context->get('last_name'))
19
           $cus_info->where('last_name = ?', $last_name);
20
21
        if($email = $this->_context->get('email'))
22
           $cus_info->where('email = ?', $email);
23
24
        if($code = $this->_context->get('code'))
25
           $cus_info->where('pro_id = ?', program::find('code = ?', $code)->getone()->id);
26
    }
27
28
    $cus_info->limitpage($page, $page_size);
29
    $cus = $cus_info->getall();
30
31
    //渲染视图
32
    $this->_view['url_args'] = $this->_context->get();
33
    $this->_view['pagination'] = $cus_info->getpagination();
34
    $this->_view['cus'] = $cus;
35
}
此代码中有一处是按条件查找用户,我们可以进行前台设计一个表单让用户输入特定条件来查找用户,代码如下:
01
02
        >search >
03
04
05
06
07
      close
08
09
10
         customer id
11
12
13
14
          first name
15
16
17
18
          last name
19
20
21
22
          email address
23
24
25
26
          program code
27
28
29
30
31
        search
32
33
34
35
36
37
      _control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
38
39
40
41
42
            cust. id
43
            first name
44
            last name
45
            email address
46
            program
47
            last login
48
            action
49
50
51
52
53
54
55
56
57
58
59
60
61
            title=view>view
62
63
64
65
66
67
68
      _control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
69
分页关键代码为:1
_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
显示结果如图:
作者:frylan
http://www.bkjia.com/phpjc/478118.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/478118.htmltecharticle当列出查找的内容有很多条的时候我们可以将数据进行分页显示。 user表的结构如图: 现在要将用户以列表的形式显示,显然不可能将查询...
其它类似信息

推荐信息