


Detailed explanation of statistical data functions implemented in PHP
This article mainly introduces the statistical data function implemented by PHP, and analyzes the related operating skills of PHP data query and display processing in the form of examples. Friends in need can refer to it
The examples in this article describe the implementation of PHP statistics function. Share it with everyone for your reference, the details are as follows:
Statistics is to integrate basic data.
Using sql, there are group by function, count function, order by function, etc.
sql will perform statistical analysis on the collected data.
Under normal circumstances, the data obtained after SQL processing must be organized through PHP logic.
Display to the front desk in a certain format.
It is generally displayed in the form of an array, which is also the concept of data structure.
Looking at this picture, the basic structure is probably
{Number of online lines, total number of orders issued, total number of verifications, total per capita, total verification rate , {(Agent 1, work number 1, number of orders 1, number of shipments 1, order approval rate 1), (Agent 2, job number 2, number of orders 2, number of shipments 2, order approval rate 2)} }
If you use PHP to display the above structure, it will be easy to handle.
First get the data processed for the first time through sql.
Don’t underestimate the data processed for the first time. If it is processed well, it will be very convenient.
Copy code The code is as follows:
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 idea, The order table is classified by user.
Get the total number of order submissions for each person on the day count().
Also get the total number of approved orders for each person and filter by where.
Then associate and query other related data.
With these basic data, other related data can be released.
Process the acquisition through php, and the variable names should be clear, which is also helpful for reading the code.
$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); }
where outData is the type of data structure to be output.
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 )
After obtaining the data, everything is easier.
Just insert it into the page, and then debug it yourself.
<!-- begin --> <?php foreach ($outData as $k => $v) { ?> <p class="col-xs-12 col-sm-6 widget-container-col ui-sortable"> <p class="widget-box widget-color-blue"> <p class="widget-header"> <h5 class="widget-title bigger lighter"> <i class="ace-icon fa fa-table"></i> 【<?php echo $v['group_name'];?>】成绩表 </h5> </p> <p class="widget-body"> <p 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> </p> </p> </p> </p> <?php }?> <!-- end -->
Related recommendations:
Example of website directory scanning index tool based on PHP
Custom array sorting function and sorting class method implemented in PHP
File operation class and file download function implemented in PHP
The above is the detailed content of Detailed explanation of statistical data functions implemented in PHP. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
