gpt4 book ai didi

Zend Framework框架实现类似Google搜索分页效果

转载 作者:qq735679552 更新时间:2022-09-27 22:32:09 28 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Zend Framework框架实现类似Google搜索分页效果由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

本文实例讲述了Zend Framework框架实现类似Google搜索分页效果。分享给大家供大家参考,具体如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
*
* @param unknown_type $model 表类型
* @param unknown_type $ncontroller 那个控制器提交的controller
* @param unknown_type $naction 那个action提交的action
*/
public function fenyepage2( $model , $ncontroller , $naction ){
     if (!isset( $_SESSION ))
     {session_start();}
     $pageSize = $_SESSION [ 'pagesize' ];
     $pageNow = $_SESSION [ 'pagenow' ];
     $offset = ( $pageNow -1)* $pageSize ;
     $db = $this ->getAdapter();
     $select = $db ->select();
     $select ->from( 'student' , '*' );
     if (!isset( $_SESSION ))
     {session_start();}
     if ( $_SESSION [ 'qsname' ]!= "" ){
       $sname = $_SESSION [ 'qsname' ];
       $select ->where( 'sname like ?' , "%$sname%" );
     }
     if ( $_SESSION [ 'qsaddress' ]!= "" ){
       $saddress = $_SESSION [ 'qsaddress' ];
       $select ->where( 'saddress like ?' , "%$saddress%" );
     }
     if ( $_SESSION [ 'qsdept' ]!= "" ){
       $sdept = $_SESSION [ 'qsdept' ];
       $select ->where( 'sdept like ?' , "%$sdept%" );
     }
     $coutNews = $db ->fetchAll( $select );
     $pageCount = ceil ( count ( $coutNews )/ $pageSize );
     $select ->limit( $pageSize , $offset ); //第一个参数:总共显示多少个。第二个参数:从第几个开始显示
     $res = $db ->fetchAll( $select );
     $native = null;
     $native = "<a href='\\$ncontroller\\$naction?pageNow=1&pagesize=$pageSize'>首页</a>&nbsp" ;
     if ( $pageNow >1){
       $nextPage = $pageNow -1;
       $native .= "&nbsp;<a href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>上一页</a>&nbsp;" ;
     }
       if (( $pageNow -1)>5){
         if ( $pageNow +4> $pageCount ){ //如果最后的页数和理应前面开始的页数小于10则
           $start = $pageCount -9; //开始的页数和结束的页数相差9
         } else {
           $start = $pageNow -5; //开始位置和结束位置相差5
         }
       } else {
         $start = floor (( $pageNow -1)/10)*10+1;
       }
       if ( $pageCount >= $start +10){
         $index = $start +10;
       }
       else {
         $index = $pageCount +1;
       }
       for (; $start < $index ; $start ++){
         $native .= "&nbsp;&nbsp;<a href='\\$ncontroller\\$naction?pageNow=$start&pagesize=$pageSize'>$start</a>" ;
       }
     if ( $pageNow < $pageCount ){
       $nextPage = $pageNow +1;
       $native .= "&nbsp;&nbsp;<a href='\\$ncontroller\\$naction?pageNow=$nextPage&pagesize=$pageSize'>下一页</a>&nbsp;" ;
     }
     $native .= "&nbsp;&nbsp;<a href='\\$ncontroller\\$naction?pageNow=$pageCount&pagesize=$pageSize'>末页</a>&nbsp;" ;
     $native .= "&nbsp;&nbsp;当前{$pageNow}||总共{$pageCount}页" ;
     $model ->arrs = $res ;
     $model ->native = $native ;
}

希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助.

最后此篇关于Zend Framework框架实现类似Google搜索分页效果的文章就讲到这里了,如果你想了解更多关于Zend Framework框架实现类似Google搜索分页效果的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com