search
HomeBackend DevelopmentPHP TutorialDetailed explanation of statistical data functions implemented in PHP

Detailed explanation of statistical data functions implemented in PHP

Jun 01, 2018 pm 02:11 PM
phpStatistical dataDetailed explanation

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[&#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 -->

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!

Statement
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
How do you modify data stored in a PHP session?How do you modify data stored in a PHP session?Apr 27, 2025 am 12:23 AM

TomodifydatainaPHPsession,startthesessionwithsession_start(),thenuse$_SESSIONtoset,modify,orremovevariables.1)Startthesession.2)Setormodifysessionvariablesusing$_SESSION.3)Removevariableswithunset().4)Clearallvariableswithsession_unset().5)Destroythe

Give an example of storing an array in a PHP session.Give an example of storing an array in a PHP session.Apr 27, 2025 am 12:20 AM

Arrays can be stored in PHP sessions. 1. Start the session and use session_start(). 2. Create an array and store it in $_SESSION. 3. Retrieve the array through $_SESSION. 4. Optimize session data to improve performance.

How does garbage collection work for PHP sessions?How does garbage collection work for PHP sessions?Apr 27, 2025 am 12:19 AM

PHP session garbage collection is triggered through a probability mechanism to clean up expired session data. 1) Set the trigger probability and session life cycle in the configuration file; 2) You can use cron tasks to optimize high-load applications; 3) You need to balance the garbage collection frequency and performance to avoid data loss.

How can you trace session activity in PHP?How can you trace session activity in PHP?Apr 27, 2025 am 12:10 AM

Tracking user session activities in PHP is implemented through session management. 1) Use session_start() to start the session. 2) Store and access data through the $_SESSION array. 3) Call session_destroy() to end the session. Session tracking is used for user behavior analysis, security monitoring, and performance optimization.

How can you use a database to store PHP session data?How can you use a database to store PHP session data?Apr 27, 2025 am 12:02 AM

Using databases to store PHP session data can improve performance and scalability. 1) Configure MySQL to store session data: Set up the session processor in php.ini or PHP code. 2) Implement custom session processor: define open, close, read, write and other functions to interact with the database. 3) Optimization and best practices: Use indexing, caching, data compression and distributed storage to improve performance.

Explain the concept of a PHP session in simple terms.Explain the concept of a PHP session in simple terms.Apr 26, 2025 am 12:09 AM

PHPsessionstrackuserdataacrossmultiplepagerequestsusingauniqueIDstoredinacookie.Here'showtomanagethemeffectively:1)Startasessionwithsession_start()andstoredatain$_SESSION.2)RegeneratethesessionIDafterloginwithsession_regenerate_id(true)topreventsessi

How do you loop through all the values stored in a PHP session?How do you loop through all the values stored in a PHP session?Apr 26, 2025 am 12:06 AM

In PHP, iterating through session data can be achieved through the following steps: 1. Start the session using session_start(). 2. Iterate through foreach loop through all key-value pairs in the $_SESSION array. 3. When processing complex data structures, use is_array() or is_object() functions and use print_r() to output detailed information. 4. When optimizing traversal, paging can be used to avoid processing large amounts of data at one time. This will help you manage and use PHP session data more efficiently in your actual project.

Explain how to use sessions for user authentication.Explain how to use sessions for user authentication.Apr 26, 2025 am 12:04 AM

The session realizes user authentication through the server-side state management mechanism. 1) Session creation and generation of unique IDs, 2) IDs are passed through cookies, 3) Server stores and accesses session data through IDs, 4) User authentication and status management are realized, improving application security and user experience.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function