Home > Backend Development > PHP Tutorial > Detailed explanation of statistical data functions implemented in PHP

Detailed explanation of statistical data functions implemented in PHP

不言
Release: 2023-03-29 07:42:01
Original
4874 people have browsed it

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);
}
Copy after login


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
)
Copy after login


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[&#39;group_name&#39;];?>】成绩表
      </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[&#39;stat&#39;][&#39;online_count&#39;]?></td>
            </tr>
            <tr>
              <td colspan="2">出单总数:</td>
              <td style="color:red"><?php echo $v[&#39;stat&#39;][&#39;all_subcount&#39;]?></td>
              <td >核过总数</td>
              <td style="color:red"><?php echo $v[&#39;stat&#39;][&#39;all_passcount&#39;]?></td>
            </tr>
            <tr>
              <td colspan="2">总人均:</td>
              <td style="color:red"><?php echo $v[&#39;stat&#39;][&#39;average_subcount&#39;]?></td>
              <td >总核率</td>
              <td style="color:red"><?php echo $v[&#39;stat&#39;][&#39;all_passrate&#39;]?></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[&#39;stat&#39;][&#39;list&#39;] as $listk => $listv) { ?>
            <tr>
              <td class=""><?php echo $listv[&#39;full_name&#39;]?></td>
              <td>
                <a href="#"><?php echo $listv[&#39;user&#39;]?></a>
              </td>
              <td class="">
                <a href="#"><?php echo $listv[&#39;subcount&#39;]?></a>
              </td>
              <td class=""><?php echo $listv[&#39;passcount&#39;]?></td>
              <td class=""><?php echo $listv[&#39;passrate&#39;]?></td>
            </tr>
            <?php }?>
            <tr style="color:red;font-size:16px">
                <td class=""colspan="2">总计</td>
                <td class=""><?php echo $v[&#39;stat&#39;][&#39;all_subcount&#39;]?></td>
                <td class=""><?php echo $v[&#39;stat&#39;][&#39;all_passcount&#39;]?></td>
                <td class=""><?php echo $v[&#39;stat&#39;][&#39;all_passrate&#39;]?></td>
            </tr>
          </tbody>
        </table>
      </p>
    </p>
  </p>
</p>
<?php }?>
<!-- end -->
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template