ThinkPHP statistics ranking and paging display function example, thinkphp paging display
This article analyzes thinkPHP's statistical ranking and paging display functions. We will share this with you for your reference. The details are as follows:
1. Paging Parameters
Count |
Total |
FirstRow |
Start line |
ListRows |
Number of records retrieved each time |
List |
Records on each page (to be consistent with count) |
2. Paging object
Real Data Tables
It can also be used for statistical data tables, or virtual tables.
Because LIMIT is the final execution, even if you perform group operations, even if you perform subqueries
Html
<Include file = "Public: head" title = ""/> <style type = "text/css">. top {font-size: 18px; border-bottom: # ddd 1px solid; margin-bottom:-1px; font-weight: bold ;}. top. title {margin: 10px; border: 1px solid # EF6C00; display:-webkit-box; border-radius: 3px ;}. top. title. title_child {width: 50%; line-height: 40px;-webkit-box-flex: 1; display: block; color: # EF6C00; text-decoration: none ;}. top. title. title_child.active {color: # FFF; background: # EF6C00 ;}. page {margin-right: 10px ;}. ranknum {font-weight: bold; color: # F92672 ;}# myrank {color: # FFF; font-weight: bold; background-color: # FBC853 ;} </style> <script type = "text/javascript"> </script> <body> <div class = "top text-center"> <div class = "title"> <a class = "title_child <if condition = '$ type neq 1'> active </if>" href = "{sh:: U ('user/ranklist', array ('type' => 0 ))} "> monthly ranking </a> <a class =" title_child <if condition = '$ type eq 1'> active </if> "href =" {sh :: U ('user/ranklist', array ('type' => 1 ))} "> total ranking </a> </div> <div id =" myrank "class =" alert-danger text-center "> Number of Merchants: {sh: $ my_user_count} current ranking: {sh: $ my_rank} </div> <div id = "datalist"> <table class = "table-hover"> <thead> <tr> <th >#</th> <th> name </th> <th> Number of merchants </th> </tr> </thead> <tbody> <volist name = "list" id = "vo"> <tr> <th scope = "row" class = "ranknum"> <if condition = "$ vo. rank eq 1 "> <elseif condition =" $ vo. rank eq 2 "/> <elseif condition =" $ vo. rank eq 3 "/> <else/> {sh: $ vo. rank} </if> </th> <td> {sh: $ vo. name} </td> <td> {sh: $ vo. usercount }</td> </tr> </volist> </tbody> </table> <div class = "page text-right"> {sh: $ page} </div> </body>
Php
// Ranking public function ranklist () {$ type = $ this-> _ get ('type', 'trim'); $ this-> assign ('type ', $ type); $ opener_id = $ this-> opener_id; if ($ type = 0) {// last month's ranking $ arrLastMonth = $ this-> getLastMonthStartEndDay (); $ lastStartDay = $ arrLastMonth ['laststartday']; $ lastEndDay = $ arrLastMonth ['lastendday']. '23:59:59 '; $ B _time = strtotime ($ lastStartDay); $ e_time = strtotime ($ lastEndDay); $ where [' B. addtime'] = arr Ay (array ('gt ', $ B _time), array ('lt', $ e_time), 'and');} $ where ['a. status '] = array ('eq', '1'); M ()-> query ('set @ rank = 0; '); $ subQuery = M () -> table ('sh _ opener A')-> join ('sh _ user B on. id = B. opener_id ')-> where ($ where)-> group ('a. id')-> order ('usercount desc')-> field ('a. id, count (B. id) as usercount,. name')-> select (false); $ all = M ()-> table (''. $ subQuery. 'A')-> getField ('a. id,. usercount,. name, (@ rank: = FN ULL (@ rank, 0) + 1) as rank '); $ count = count ($ all); $ Page = new Page ($ count, 10 ); $ list = M ()-> table ('sh _ opener A')-> join ('sh _ user B on. id = B. opener_id ')-> where ($ where)-> group ('a. id')-> order ('usercount desc')-> limit ($ Page-> firstRow. ','. $ Page-> listRows)-> field ('count (B. id) as usercount,. name,. id')-> select (); foreach ($ list as $ k => $ v) {$ list [$ k] ['rank '] = $ k + 1 + $ Page-> firstRow;} // my merchant $ my _ User_count = $ all [$ opener_id] ['usercount']? $ All [$ opener_id] ['usercount']: 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 ();} // obtain the private function getLastMonthStartEndDay () from the last month and the end date () {$ thismonth = date ('M'); $ thisyear = date ('y'); if ($ thismonth = 1) {$ lastmonth = 12; $ lastyear = $ thisyear-1;} else {$ lastmonth = $ thismonth-1; $ lastyear = $ thisyear;} $ lastStartDay = $ lastyear. '-'. $ lastmonth. '-1'; $ lastEndDay = $ lastyear. '-'. $ lastmonth. '-'. date ('T', strtotime ($ lastStartDay); // t specifies the number of days of the month, 28 to 31 return array ('laststartday' => $ lastStartDay, 'lastendday' => $ lastEndDay );}
The thinkphp paging class is used here.
Case Effect