Detailed description of Statistical Data functions implemented by PHP, and detailed description of php statistical data

Source: Internet
Author: User
Tags php foreach

Detailed description of Statistical Data functions implemented by PHP, and detailed description of php statistical data

This example describes the statistical data function implemented by PHP. We will share this with you for your reference. The details are as follows:

Statistics are the integration of basic data.

SQL is used, including the group by function, count function, and order by function.

SQL will collect data for statistical analysis.

In general, the data obtained after SQL processing should be sorted through the php logic.

Display to the front-end in a certain format.

It is usually displayed as an array, which is also the concept of data structure.

Look at this picture. The structure is probably

{Number of online tickets, total number of outgoing tickets, total number of checked items, total per capita, total core rate, {(Agent 1, EMPLOYEE 1, number of outgoing tickets 1, number of deliveries 1, core ticket rate 1), (AGENT 2, employee ID 2, number of Outgoing orders 2, number of deliveries 2, number of tickets 2 )}}

If php is used to display the above structure, it will be very easy to handle.

First, obtain the first processed data through SQL,

Don't underestimate the data processed for the first time. It is very convenient to process well.
Copy codeThe Code is as follows: SELECT. 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 ('2017-11-7 ') and user_group = 'teamone' and verifysta = 'y' group by user) B on. user = B. user left join vicidial_users c on. user = c. user where time> UNIX_TIMESTAMP ('2017-11-7 ') and. user_group = 'teamone' group by. user;

The SQL logic is to classify the order table by user.

Obtain the total number of orders submitted for each day, count ().

You also need to obtain the total number of people whose orders have passed the review and filter by where.

Then query other related data.

With this basic data, other related data will be available.

Processing and obtaining through php, where the variable name should be clear, which is also conducive to reading the code.

$ Select_ SQL = "SELECT. 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. user = B. user left join vicidial_users c on. user = c. user where time> UNIX_TIMESTAMP ('". $ today. "') and A. user_group = '". $ user_group. "'group BY. 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 )) // retrieve the key value data mysqli_fetch_field obtain a data mysqli_fetch_fields obtain multiple sets of data 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 is the data structure type to be output.

Array ([list] => Array ([0] => Array ([user] => 8001 [full_name] => Wei Shuo Lei [subcount] => 3 [passcount] => 2 [passrate] = & gt; 67%) [1] => Array ([user] => 8004 [full_name] => Liu Qing [subcount] => 2 [passcount] => 2 [passrate] => 100%) [2] => Array ([user] => 8005 [full_name] => Zhang houying [subcount] => 4 [passcount] => 3 [passrate] => 75%)) [all_subcount] => 9 [all_passcount] => 7 [all_passrate] => 78% [online_count] => 3 [average_subcount] => 3)

After obtaining data, everything is easy.

You can set the page and debug it yourself.

<! -- 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 "> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.