《PHP应用:PHP实现的统计数据功能详解》要点:
本文介绍了PHP应用:PHP实现的统计数据功能详解,希望对您有用。如果有疑问,可以联系我们。
PHP应用本文实例讲述了PHP实现的统计数据功能.分享给大家供大家参考,具体如下:
PHP应用统计,就是把基本的数据,整合起来.
PHP应用用到sql的,有group by 功能,count功能,order by功能等等.
PHP应用sql将收集的数据,进行统计分析.
PHP应用一般情况下,sql处理后得到的数据,还要通过php的逻辑来进行整理.
PHP应用以一定的格式,展示到前台.
PHP应用一般都是以数组的方式展示,这也是数据结构的概念.
PHP应用
PHP应用看这张图片,基本想想结构大概为
PHP应用{上线数,出单总数,核过总数,总人均,总核率,{(坐席人1,工号1,出单数1,发货数1,核单率1),(坐席人2,工号2,出单数2,发货数2,核单率2)}}
PHP应用如果用php展示成上面的结构的话,就很好处理了.
PHP应用首先通过sql获取初次处理的数据,
PHP应用别小看这初次处理的数据,处理的好,会非常的便捷.
PHP应用sql思路,归类订单表,以user来进行归类.
PHP应用获取每个人,当天的订单提交总数count().
PHP应用还要获取每个人,订单通过审核的总数,通过where筛选.
PHP应用然后关联查询其他相关数据.
PHP应用
PHP应用有了这些基本数据,其他的相关数据都能出来了.
PHP应用通过php来处理获取,其中变量命名要清晰,这样也有利于阅读代码.
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);
}
PHP应用其中outData就是要输出的数据结构类型.
PHP应用
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
)
PHP应用获取数据后,一切都好办了.
PHP应用套入页面就可以了,然后自己再调试调试.
PHP应用
<!-- 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'];?>】成绩表
</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">上线总人数:</td>
<td colspan="3"><?php echo $v['stat']['online_count']?></td>
</tr>
<tr>
<td colspan="2">出单总数:</td>
<td style="color:red"><?php echo $v['stat']['all_subcount']?></td>
<td >核过总数</td>
<td style="color:red"><?php echo $v['stat']['all_passcount']?></td>
</tr>
<tr>
<td colspan="2">总人均:</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>
工号
</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 style="color:red;font-size:16px">
<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应用更多关于PHP相关内容感兴趣的读者可查看本站专题:《php+mysql数据库操作入门教程》、《PHP基于pdo操作数据库技巧总结》、《PHP+MongoDB数据库操作技巧大全》、《php+Oracle数据库程序设计技巧总结》、《php+mssql数据库程序设计技巧总结》、《php+redis数据库程序设计技巧总结》、《php+mysqli数据库程序设计技巧总结》及《php常见数据库操作技巧汇总》
PHP应用希望本文所述对大家PHP程序设计有所帮助.
转载请注明本页网址:
http://www.vephp.com/jiaocheng/2489.html