您好,登录后才能下订单哦!
怎么在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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。