thinkphp statistics ranking and pagination Display function Example _php instance

Source: Internet
Author: User
Tags php template codeigniter zend framework

This article analyzes the thinkphp statistics ranking and paging display function. Share to everyone for your reference, specific as follows:

1. Paging parameters

Count Total
FirstRow Start line
ListRows Get the number of records per time
List The records for each page (to match the count)

2. Paging objects

Can be used for real data tables.
You can also focus on a statistically available datasheet, or virtual table.
Because limit is the last execution, even if you do a group operation, even if you do subquery

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)} ' > Month 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> <div id= "Myrank" class= "alert Alert-danger text-center" > My merchant Number: {sh: $my _user_count}  & nbsp Current rank: {sh: $my _rank} </div> <div id= "DataList" > <table class= "Table Table-hover" > <thead> &L t;tr> <th>  #</th> <th> name </th> <th> merchant number </th> </tr&gt
   ; </thead> <tbody> <volist name= "list" id= "Vo" > <tr> <th scope= "Row" class= "rank num "> <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}& lt;/td> </tr> </volist> </tbody> </table> <div class= "page Text-right" > {s

 H: $page} </div> </div> </body>  

PHP

List public Function ranklist () {$type = $this->_get (' type ', ' trim ');
    $this->assign (' type ', $type);
    $opener _id = $this->opener_id;
      if ($type = = 0) {//last month ranking $arrLastMonth = $this->getlastmonthstartendday ();
      $lastStartDay = $arrLastMonth [' Laststartday ']; $lastEndDay = $arrLastMonth [' Lastendday ']. 
      23:59:59 ';
      $b _time = Strtotime ($lastStartDay);
      $e _time = Strtotime ($lastEndDay); 
    $where [' b.addtime '] = 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 a.id = b.opener_id ')->where ($where)->group (' a.ID
    ')->order (' UserCount desc ')->field (' A.id,count (b.id) as Usercount,a.name ')->select (false);
    $all = M ()->table ('. $subQuery. ' A ')->getfield (' A.id,a.usercount,a.name, (@rank: =ifnull (@rank, 0) +1) as Rank ');
    $count = count ($all); $Page = new Page ($cOunt, 10); $list = M ()->table (' Sh_opener a ')->join (' Sh_user b on a.id = b.opener_id ')->where ($where)->group (' a.id ')-& Gt;order (' UserCount desc ')->limit ($Page->firstrow. ', '. $Page->listrows)->field (' Count (b.id) as
    Usercount,a.name,a.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 ();
    //Get the start and end date Private function Getlastmonthstartendday () {$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 the number of days for a given month, 28 to return Array (' Laststartday ' => $lastStartDay, ' lastendday ' => $lastEndDay);

 }

This is accomplished using the Thinkphp page class.

Case effect

More interested readers of thinkphp related content can view the website topic: "thinkphp Introductory Course", "thinkphp template Operation Skill Summary", "thinkphp Common Method Summary", "The CodeIgniter Introductory Course", "CI ( CodeIgniter) Framework Advanced tutorials, introductory tutorials for the Zend framework Framework, Smarty Templates Primer tutorial, and PHP template technology summary.

I hope this article will help you with the PHP program design based on thinkphp framework.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.