PHP實(shí)現(xiàn)的統(tǒng)計(jì)數(shù)據(jù)功能詳解
本文實(shí)例講述了PHP實(shí)現(xiàn)的統(tǒng)計(jì)數(shù)據(jù)功能。分享給大家供大家參考,具體如下:
統(tǒng)計(jì),就是把基本的數(shù)據(jù),整合起來(lái)。
用到sql的,有g(shù)roup by 功能,count功能,order by功能等等。
sql將收集的數(shù)據(jù),進(jìn)行統(tǒng)計(jì)分析。
一般情況下,sql處理后得到的數(shù)據(jù),還要通過(guò)php的邏輯來(lái)進(jìn)行整理。
以一定的格式,展示到前臺(tái)。
一般都是以數(shù)組的方式展示,這也是數(shù)據(jù)結(jié)構(gòu)的概念。
看這張圖片,基本想想結(jié)構(gòu)大概為
{上線數(shù),出單總數(shù),核過(guò)總數(shù),總?cè)司偤寺?,{(坐席人1,工號(hào)1,出單數(shù)1,發(fā)貨數(shù)1,核單率1),(坐席人2,工號(hào)2,出單數(shù)2,發(fā)貨數(shù)2,核單率2)}}
如果用php展示成上面的結(jié)構(gòu)的話,就很好處理了。
首先通過(guò)sql獲取初次處理的數(shù)據(jù),
別小看這初次處理的數(shù)據(jù),處理的好,會(huì)非常的便捷。
sql思路,歸類訂單表,以u(píng)ser來(lái)進(jìn)行歸類。
獲取每個(gè)人,當(dāng)天的訂單提交總數(shù)count()。
還要獲取每個(gè)人,訂單通過(guò)審核的總數(shù),通過(guò)where篩選。
然后關(guān)聯(lián)查詢其他相關(guān)數(shù)據(jù)。
有了這些基本數(shù)據(jù),其他的相關(guān)數(shù)據(jù)都能出來(lái)了。
通過(guò)php來(lái)處理獲取,其中變量命名要清晰,這樣也有利于閱讀代碼。
$select_sql = "SELECT a.user,count(order_id) as subcount,b.passcount,c.full_name from vicidial_order a LEFT JOIN (SELECT user,count(order_id) as passcount from vicidial_order where time > UNIX_TIMESTAMP('".$today."') and user_group = '".$user_group."' and verifysta = 'Y' GROUP BY user ) b on a.user = b.user LEFT JOIN vicidial_users c on a.user = c.user where time > UNIX_TIMESTAMP('".$today."') and a.user_group = '".$user_group."' GROUP BY a.user "; $rows = mysqli_query( $db_conn, $select_sql ); $row_counts_list = mysqli_num_rows( $rows ); if ( $row_counts_list != 0 ) { $i = 0; while($rs = mysqli_fetch_assoc( $rows )) // mysqli_fetch_assoc 獲取鍵值數(shù)據(jù) mysqli_fetch_field 獲取一條數(shù)據(jù) mysqli_fetch_fields 獲取多組數(shù)據(jù) mysqli_fetch_row { $outData['list'][$i]['user'] = $rs['user']; $outData['list'][$i]['full_name'] = $rs['full_name']; $outData['list'][$i]['subcount'] = $rs['subcount']; $outData['list'][$i]['passcount'] = $rs['passcount']; $outData['list'][$i]['passrate'] = round(($rs['passcount']/$rs['subcount'])*100)."%"; $outData['all_subcount'] += $rs['subcount']; $outData['all_passcount'] += $rs['passcount']; $i++; } $outData['all_passrate'] = round(($outData['all_passcount']/$outData['all_subcount'])*100)."%"; $outData['online_count'] = $row_counts_list; $outData['average_subcount'] = round($outData['all_subcount']/$outData['online_count'],1); }
其中outData就是要輸出的數(shù)據(jù)結(jié)構(gòu)類型。
Array ( [list] => Array ( [0] => Array ( [user] => 8001 [full_name] => 魏碩磊 [subcount] => 3 [passcount] => 2 [passrate] => 67% ) [1] => Array ( [user] => 8004 [full_name] => 劉慶 [subcount] => 2 [passcount] => 2 [passrate] => 100% ) [2] => Array ( [user] => 8005 [full_name] => 章厚英 [subcount] => 4 [passcount] => 3 [passrate] => 75% ) ) [all_subcount] => 9 [all_passcount] => 7 [all_passrate] => 78% [online_count] => 3 [average_subcount] => 3 )
獲取數(shù)據(jù)后,一切都好辦了。
套入頁(yè)面就可以了,然后自己再調(diào)試調(diào)試。
<!-- begin --> <?php foreach ($outData as $k => $v) { ?> <div class="col-xs-12 col-sm-6 widget-container-col ui-sortable"> <div class="widget-box widget-color-blue"> <div class="widget-header"> <h5 class="widget-title bigger lighter"> <i class="ace-icon fa fa-table"></i> 【<?php echo $v['group_name'];?>】成績(jī)表 </h5> </div> <div class="widget-body"> <div class="widget-main no-padding"> <table> </table> <table class="table table-striped table-bordered table-hover"> <thead style="text-align:center;font-size:16px"> <tr> <td colspan="2">上線總?cè)藬?shù):</td> <td colspan="3"><?php echo $v['stat']['online_count']?></td> </tr> <tr> <td colspan="2">出單總數(shù):</td> <td style="color:red"><?php echo $v['stat']['all_subcount']?></td> <td >核過(guò)總數(shù)</td> <td style="color:red"><?php echo $v['stat']['all_passcount']?></td> </tr> <tr> <td colspan="2">總?cè)司?lt;/td> <td style="color:red"><?php echo $v['stat']['average_subcount']?></td> <td >總核率</td> <td style="color:red"><?php echo $v['stat']['all_passrate']?></td> </tr> </thead> <thead class="thin-border-bottom"> <tr> <th> <i class="ace-icon "></i> 坐席人 </th> <th> <i class="ace-icon "></i> 工號(hào) </th> <th> <i class="ace-icon "></i> 出單數(shù) </th> <th> <i class="ace-icon "></i> 發(fā)貨數(shù) </th> <th> <i class="ace-icon "></i> 核單率 </th> </tr> </thead> <tbody> <?php foreach ($v['stat']['list'] as $listk => $listv) { ?> <tr> <td class=""><?php echo $listv['full_name']?></td> <td> <a href="#"><?php echo $listv['user']?></a> </td> <td class=""> <a href="#"><?php echo $listv['subcount']?></a> </td> <td class=""><?php echo $listv['passcount']?></td> <td class=""><?php echo $listv['passrate']?></td> </tr> <?php }?> <tr style="color:red;font-size:16px"> <td class=""colspan="2">總計(jì)</td> <td class=""><?php echo $v['stat']['all_subcount']?></td> <td class=""><?php echo $v['stat']['all_passcount']?></td> <td class=""><?php echo $v['stat']['all_passrate']?></td> </tr> </tbody> </table> </div> </div> </div> </div> <?php }?> <!-- end -->
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫(kù)操作入門教程》、《PHP基于pdo操作數(shù)據(jù)庫(kù)技巧總結(jié)》、《PHP+MongoDB數(shù)據(jù)庫(kù)操作技巧大全》、《php+Oracle數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》、《php+mssql數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》、《php+redis數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》、《php+mysqli數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
- PHP中文處理 中文字符串截取(mb_substr)和獲取中文字符串字?jǐn)?shù)
- php中3種方法統(tǒng)計(jì)字符串中每種字符的個(gè)數(shù)并排序
- php實(shí)現(xiàn)統(tǒng)計(jì)網(wǎng)站在線人數(shù)的方法
- php使用Session和文件統(tǒng)計(jì)在線人數(shù)
- php統(tǒng)計(jì)數(shù)組元素個(gè)數(shù)的方法
- 使用php統(tǒng)計(jì)字符串中中英文字符的個(gè)數(shù)
- php超快高效率統(tǒng)計(jì)大文件行數(shù)
- PHP統(tǒng)計(jì)目錄大小的自定義函數(shù)分享
- php簡(jiǎn)單統(tǒng)計(jì)字符串單詞數(shù)量的方法
- php簡(jiǎn)單統(tǒng)計(jì)中文個(gè)數(shù)的方法
- php實(shí)現(xiàn)的統(tǒng)計(jì)字?jǐn)?shù)函數(shù)定義與使用示例
相關(guān)文章
php實(shí)現(xiàn)隨機(jī)生成易于記憶的密碼
這篇文章主要介紹了php實(shí)現(xiàn)隨機(jī)生成易于記憶的密碼,實(shí)例分析了php生成隨機(jī)密碼的相關(guān)技巧,需要的朋友可以參考下2015-06-06php簡(jiǎn)單統(tǒng)計(jì)字符串單詞數(shù)量的方法
這篇文章主要介紹了php簡(jiǎn)單統(tǒng)計(jì)字符串單詞數(shù)量的方法,涉及php字符串分割與數(shù)組統(tǒng)計(jì)的相關(guān)技巧,需要的朋友可以參考下2015-06-06PHP使用DirectoryIterator顯示下拉文件列表的方法
這篇文章主要介紹了PHP使用DirectoryIterator顯示下拉文件列表的方法,涉及php使用DirectoryIterator操作文件的技巧,需要的朋友可以參考下2015-03-03