Home > Article > Backend Development > How to ensure that the statistical data in php is correct
The example in this article describes the statistical data function implemented by PHP. I share it with you 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 and so on.
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. (Recommended learning: PHP programming from entry to proficiency)
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 roughly
{number of online lines, total number of orders, total number of verifications, total average per capita, total verification rate, {(seat number 1 , Job number 1, number of orders issued 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.
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, classify the order table, and classify it 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); }
The above is the detailed content of How to ensure that the statistical data in php is correct. For more information, please follow other related articles on the PHP Chinese website!