讀古今文學網 > 微信公眾平台開發:從零基礎到ThinkPHP5高性能框架實踐 > 25.5.5 用戶信息統計分析 >

25.5.5 用戶信息統計分析

本項目中實現了一個簡單的用戶數據分析功能——統計用戶城市數據及排名。其相應的代碼如下。


1 public function rank
2 {
3     $arr = Db::name('user')->field('city,COUNT('city') total')->where('city','<>','')->
      group('city')->order('total desc')->limit(15)->select;
4     $this->assign('list', $arr);
5     return $this->fetch;
6 }
  

模板頁面的代碼如下。


 1 <p>
 2     <table  cellspacing="0">
 3         <thead>
 4             <tr>
 5             <th >數量</th>
 6             <th >城市</th>
 7             </tr>
 8         </thead>
 9         <tbody>
10             {volist name="list" key="k"}
11             <tr>
12             <td >{$rank.total}</td>
13             <td >{$rank.city}</td>
14             </tr>
15             {/volist}
16         </tbody>
17     </table>
18 </p>
  

城市信息統計頁面如圖25-7所示。

圖25-7 城市統計列表