手机版

thinkPHP统计排行与分页显示功能示例

时间:2021-09-07 来源:互联网 编辑:宝哥软件园 浏览:

本文实例分析了thinkPHP统计排行与分页显示功能。分享给大家供大家参考,具体如下:

1.分页参数

数数总数第一行起始行列表行每一次获取记录数目录每一页的记录(要与数数对应一致就行) 2.分页对象

可以针对真实的数据表也可以针对统计出来的数据表,或者说是虚拟的表因为限制是最后执行的,哪怕你进行组操作,哪怕你进行子查询

超文本标记语言

包括文件=' public : HeAd ' title=' '/style type=' text/CSS ' .top { font-size : 18px边框-底部: #ddd 1px实心;保证金-底部:-1px;字体粗细:粗体;}.顶部。标题{ margin:10pxborder:1px实心# EF6C00display :-web套件-盒子;边界半径: 3px}.顶部。标题title _ child { width : 50%;线高:40 px-web套件-box-flex :1;显示:块;color: # EF6C00文本装饰:无;}.顶部。标题标题_孩子。主动{ color : # FFF;背景# EF6C00}。页面{ margin-right : 10px;}.ranknum { font-weight : bold;color: # F92672} #我的排名{ color : # FFF;字体粗细:加粗;背景色-: # FBC 853;}/style script type=' text/JavaScript '/scriptbodydiv class=' top text-center ' div class=' title ' a class=' title _ child if condition=' $ type neq 1 ' active/if ' href=' { sh 3360: u(' User/ranklist ',array('type'=0))} '月排行/a class=' title _ child if条件=' $ type eq 1 '活动/if ' href=' { sh 3360: u(' User/ranklist ',array('type'=1))} '总排行/a/div/div div id=' my rank ' class=' alert alert-dance text-center '我的商户数:{sh:$my_user_count}当前排名: { sh : $ my _ rank }/div div id=' datalist ' table class=' table table-hover '和tr th#/th姓名/th商户数/th/tr/ad t正文volist name=' list ' id=' VO ' tr th作用域=' row ' class=' ranknum ' if条件=' $ VO。 排名eq 1 ' img src=' http :3360 REs } public/img/gold。png ' style=' width : 30pxelseif条件=' $ VO。排名eq 2 '/img src=' http : { sh 3360: REs } public/img/silver。png ' style=' width : 30pxelseif条件=' $ VO。rank eq 3 '/img src=' http : { sh 3360: REs } public/img/copper。png ' style=' width : 30pxelse/{ sh : $ VO。排名}/if/th TD { sh : $ VO。名称}/TD { sh : $ VO。用户数}/TD/tr/volist/t body/tablediv class=' page text-right ' { sh : $ page }/div/div/body/html PHP

//排行榜public function rank list(){ $ type=$ this-_ get(' type ',' trim ');$this-assign('type ',$ type);$ open er _ id=$ this-open er _ id;if($type==0){ //上月排行$ arrlastmonthony=$ this-getLastMonthStartEndDay();$ LastStartDay=$ arrLastMountain[' LastStartDay '];$最后一天=$最后一个月['最后一天'].' 23:59:59';$ b _ time=strtotime($ LastStartDay);$ e _ time=strtotime($ LastendDay);$其中['b.addtime']=array(array('gt ',$b_time),array('lt ',$e_time),'和');} $其中['a.status']=array('eq ',' 1 ');m()-查询(' SET @ rank=0;');$ subQuery=M()-表(' sh _ opener a ')-联接(' sh _ user b on a . id=b . opener _ id ')-其中($ where)-组(' a . id ')-顺序(' user count desc ')-字段(' a . id,count(b.id)为用户计数,a . name ')-select(false);$ all=M()-表(')。$ SUChINA .a')-getField('a.id,a.usercount,a.name,(@rank:=IFNULL(@rank,0) 1)作为rank’);$ count=count($ all);$Page=新页面($count,10);$ list=M()-表(' sh _ opener a ')-联接(' sh _ user b on a . id=b . opener _ id ')-其中($ where)-组(' a . id ')-顺序('用户计数desc ')-限制($ Page-第一行).','.$ Page-listRows)-字段(' count(b.id)为usercount,a.name,a . id ')-select();foreach($ list as $ k=$ v){ $ list[$ k][' rank ']=$ k $ 1 $ Page-第一行;} //我的商户$ my _ user _ count=$ all[$ opener _ id][' user count ']?$ all[$ opener _ id]['用户计数']:0;$ my _ rank=$ all[$ opener _ id][' rank ']?$ all[$ opener _ id][' rank ']: '-';$this-assign('my_user_count ',$ my _ user _ count);$this-assign('my_rank ',$ my _ rank);$this-assign('page ',$ Page-show());$this-assign('list ',$ list);$ this-display();}//获取上一月开始与结束日期私有函数getLastMonthStartEndDay(){ $本月=日期(' m ');$今年=日期(' Y ');if($本月==1){ $上个月=12;$去年=$今年-1;} else { $上个月=$本月-1;$ lastyear=$今年} $ lastStartDay=$ lastyear .'-' .上个月。'-1';$lastEndDay=$lastyear .'-' .上个月。'-' .日期(' t ',strtotime($ LastStartDay));//t给定月份所应有的天数,28到31返回数组(' lastStartDay '=$ lastStartDay,' last endday '=$ last endday);}这里用的是thinkphp的分页类实现的。

案例效果

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题: 《ThinkPHP入门教程》 、 《thinkPHP模板操作技巧总结》 、 《ThinkPHP常用方法总结》 、 《codeigniter入门教程》 、 《CI(CodeIgniter)框架进阶教程》 、 《Zend FrameWork框架入门教程》 、 《smarty模板入门基础教程》 及《PHP模板技术总结》 。

希望本文所述对大家基于ThinkPHP框架的服务器端编程语言(专业超文本预处理器的缩写)程序设计有所帮助。

版权声明:thinkPHP统计排行与分页显示功能示例是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。