PHP implementation of statistical data features detailed _php skills

Source: Internet
Author: User
Tags data structures php foreach oracle database

This article illustrates the statistical data function of PHP implementation. Share to everyone for your reference, specific as follows:

Statistics, is to integrate the basic data.

SQL, with the group by function, Count function, order by function, and so on.

SQL will collect the data for statistical analysis.

In general, the data obtained after SQL processing, but also through the logic of PHP to organize.

In a certain format, show to the front desk.

are generally presented as arrays, which is also the concept of data structures.

Look at this picture, basically think about the structure

{The number of online, the total number of orders, total number of nuclear power, total per capita, total nuclear rate, {(seat 1, Work No. 1, singular 1, shipment 1, nuclear single rate 1), (seat 2, work number 2, out singular 2, shipping number 2, nuclear single rate 2)}

If you use PHP to show the structure of the above, it is very good to deal with.

First processed data is obtained through SQL.

Do not underestimate this initial processing data, the processing is good, will be very convenient.

Copy Code code 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 Veri Fysta = ' Y ' GROUP by user] B on a.user = B.user left JOIN vicidial_users c to A.user = C.user where time > Unix_timest AMP (' 2015-11-7 ') and A.user_group = ' Teamone ' GROUP by A.user;

SQL ideas, collation Order table, user to classify.

Get everyone, the number of orders submitted for the day count ().

Also to get everyone, the total number of orders through the audit, through where to filter.

It then associates the query with other related data.

With these basic data, other relevant data are available.

Using PHP to process access, where variable naming is clear, this also facilitates reading 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 = '". $US Er_group. "' and Verifysta = ' Y ' GROUP by user" B on a.user = B.user left JOIN vicidial_users c on a.user = C.user where T IME > 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 Get key value data Mysqli_fetch_field get a data mysqli_fetch_fields get multiple groups
    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);

 }

Where Outdata is the type of data structure to output.

Array
(
  [list] => array ([
      0] => array
        (
          [user] => 8001
          [full_name] => Wei
          [Subcount] => 3
          [Passcount] => 2
          [passrate] => 67%
        )
      [1] => Array
        (
          [user] => 8004
          [Full_ Name] => Liu Qing
          [Subcount] => 2
          [Passcount] => 2
          [passrate] => 100%
        )
      [2] => array< c21/> (
          [user] => 8005
          [full_name] => Zhang Huoying
          [Subcount] => 4
          [Passcount] => 3
          [ Passrate] => 75%
        )
    )
  [All_subcount] => 9
  [All_passcount] => 7
  [all_passrate] => 78%
  [Online_count] => 3
  [Average_subcount] => 3
)

After getting the data, everything is fine.

You can set the page, and then debug your own debugging.

<!--begin--> <?php foreach ($outData as $k => $v) {?> <div class= "col-xs-12 col-sm-6 widget-containe R-col ui-sortable "> <div class=" Widget-box widget-color-blue "> <div class=" Widget-header "> <  H5 class= "widget-title bigger Lighter" > <i class= "ace-icon fa fa-table" ></i> "<?php Echo $v [' group_name '];? > "Performance table  

More interested in PHP related content readers can view the site topics: "Php+mysql Database Operation Introduction Tutorial", "PHP based on PDO Operation Database Skills Summary", "PHP+MONGODB Database Operation Skills Encyclopedia", "php+ Oracle Database Programming Skills Summary, "PHP+MSSQL Database Programming Skills Summary", "Php+redis Database Programming Skills Summary", "PHP+MYSQLI Database Programming Skills Summary" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design.

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.