您好,登錄后才能下訂單哦!
怎么在PHP項目中實現一個統計數據功能?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
首先通過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('2015-11-7') and user_group = 'TeamOne' 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('2015-11-7') and a.user_group = 'TeamOne' GROUP BY a.user ;
sql思路,歸類訂單表,以user來進行歸類。
獲取每個人,當天的訂單提交總數count()。
還要獲取每個人,訂單通過審核的總數,通過where篩選。
然后關聯查詢其他相關數據。
有了這些基本數據,其他的相關數據都能出來了。
通過php來處理獲取,其中變量命名要清晰,這樣也有利于閱讀代碼。
$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 獲取鍵值數據 mysqli_fetch_field 獲取一條數據 mysqli_fetch_fields 獲取多組數據 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就是要輸出的數據結構類型。
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 )
獲取數據后,一切都好辦了。
套入頁面就可以了,然后自己再調試調試。
<!-- 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"> <h6 class="widget-title bigger lighter"> <i class="ace-icon fa fa-table"></i> 【<?php echo $v['group_name'];?>】成績表 </h6> </div> <div class="widget-body"> <div class="widget-main no-padding"> <table> </table> <table class="table table-striped table-bordered table-hover"> <thead > <tr> <td colspan="2">上線總人數:</td> <td colspan="3"><?php echo $v['stat']['online_count']?></td> </tr> <tr> <td colspan="2">出單總數:</td> <td ><?php echo $v['stat']['all_subcount']?></td> <td >核過總數</td> <td ><?php echo $v['stat']['all_passcount']?></td> </tr> <tr> <td colspan="2">總人均:</td> <td ><?php echo $v['stat']['average_subcount']?></td> <td >總核率</td> <td ><?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> 工號 </th> <th> <i class="ace-icon "></i> 出單數 </th> <th> <i class="ace-icon "></i> 發貨數 </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 > <td class=""colspan="2">總計</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 -->
關于怎么在PHP項目中實現一個統計數據功能問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。