欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP實(shí)現(xiàn)的統(tǒng)計(jì)數(shù)據(jù)功能詳解

 更新時(shí)間:2016年12月06日 10:44:15   作者:牛逼的霍嘯林  
這篇文章主要介紹了PHP實(shí)現(xiàn)的統(tǒng)計(jì)數(shù)據(jù)功能,結(jié)合實(shí)例形式分析了php數(shù)據(jù)查詢與顯示處理的相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了PHP實(shí)現(xiàn)的統(tǒng)計(jì)數(shù)據(jù)功能。分享給大家供大家參考,具體如下:

統(tǒng)計(jì),就是把基本的數(shù)據(jù),整合起來(lái)。

用到sql的,有g(shù)roup by 功能,count功能,order by功能等等。

sql將收集的數(shù)據(jù),進(jìn)行統(tǒng)計(jì)分析。

一般情況下,sql處理后得到的數(shù)據(jù),還要通過(guò)php的邏輯來(lái)進(jìn)行整理。

以一定的格式,展示到前臺(tái)。

一般都是以數(shù)組的方式展示,這也是數(shù)據(jù)結(jié)構(gòu)的概念。

看這張圖片,基本想想結(jié)構(gòu)大概為

{上線數(shù),出單總數(shù),核過(guò)總數(shù),總?cè)司偤寺?,{(坐席人1,工號(hào)1,出單數(shù)1,發(fā)貨數(shù)1,核單率1),(坐席人2,工號(hào)2,出單數(shù)2,發(fā)貨數(shù)2,核單率2)}}

如果用php展示成上面的結(jié)構(gòu)的話,就很好處理了。

首先通過(guò)sql獲取初次處理的數(shù)據(jù),

別小看這初次處理的數(shù)據(jù),處理的好,會(huì)非常的便捷。

復(fù)制代碼 代碼如下:
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思路,歸類訂單表,以u(píng)ser來(lái)進(jìn)行歸類。

獲取每個(gè)人,當(dāng)天的訂單提交總數(shù)count()。

還要獲取每個(gè)人,訂單通過(guò)審核的總數(shù),通過(guò)where篩選。

然后關(guān)聯(lián)查詢其他相關(guān)數(shù)據(jù)。

有了這些基本數(shù)據(jù),其他的相關(guān)數(shù)據(jù)都能出來(lái)了。

通過(guò)php來(lái)處理獲取,其中變量命名要清晰,這樣也有利于閱讀代碼。

$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 獲取鍵值數(shù)據(jù)   mysqli_fetch_field 獲取一條數(shù)據(jù) mysqli_fetch_fields 獲取多組數(shù)據(jù)  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就是要輸出的數(shù)據(jù)結(jié)構(gòu)類型。

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
)

獲取數(shù)據(jù)后,一切都好辦了。

套入頁(yè)面就可以了,然后自己再調(diào)試調(diào)試。

<!-- 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">
      <h5 class="widget-title bigger lighter">
        <i class="ace-icon fa fa-table"></i>
        【<?php echo $v['group_name'];?>】成績(jī)表
      </h5>
    </div>
    <div class="widget-body">
      <div 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">上線總?cè)藬?shù):</td>
              <td colspan="3"><?php echo $v['stat']['online_count']?></td>
            </tr>
            <tr>
              <td colspan="2">出單總數(shù):</td>
              <td style="color:red"><?php echo $v['stat']['all_subcount']?></td>
              <td >核過(guò)總數(shù)</td>
              <td style="color:red"><?php echo $v['stat']['all_passcount']?></td>
            </tr>
            <tr>
              <td colspan="2">總?cè)司?lt;/td>
              <td style="color:red"><?php echo $v['stat']['average_subcount']?></td>
              <td >總核率</td>
              <td style="color:red"><?php echo $v['stat']['all_passrate']?></td>
            </tr>
          </thead>
          <thead class="thin-border-bottom">
            <tr>
              <th>
                <i class="ace-icon "></i>
                坐席人
              </th>
              <th>
                <i class="ace-icon "></i>
                工號(hào)
              </th>
              <th>
                <i class="ace-icon "></i>
                出單數(shù)
              </th>
              <th>
                <i class="ace-icon "></i>
                發(fā)貨數(shù)
              </th>
              <th>
                <i class="ace-icon "></i>
                核單率
              </th>
            </tr>
          </thead>
          <tbody>
            <?php foreach ($v['stat']['list'] as $listk => $listv) { ?>
            <tr>
              <td class=""><?php echo $listv['full_name']?></td>
              <td>
                <a href="#"><?php echo $listv['user']?></a>
              </td>
              <td class="">
                <a href="#"><?php echo $listv['subcount']?></a>
              </td>
              <td class=""><?php echo $listv['passcount']?></td>
              <td class=""><?php echo $listv['passrate']?></td>
            </tr>
            <?php }?>
            <tr style="color:red;font-size:16px">
                <td class=""colspan="2">總計(jì)</td>
                <td class=""><?php echo $v['stat']['all_subcount']?></td>
                <td class=""><?php echo $v['stat']['all_passcount']?></td>
                <td class=""><?php echo $v['stat']['all_passrate']?></td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
<?php }?>
<!-- end -->

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《php+mysql數(shù)據(jù)庫(kù)操作入門教程》、《PHP基于pdo操作數(shù)據(jù)庫(kù)技巧總結(jié)》、《PHP+MongoDB數(shù)據(jù)庫(kù)操作技巧大全》、《php+Oracle數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》、《php+mssql數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》、《php+redis數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》、《php+mysqli數(shù)據(jù)庫(kù)程序設(shè)計(jì)技巧總結(jié)》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • php實(shí)現(xiàn)隨機(jī)生成易于記憶的密碼

    php實(shí)現(xiàn)隨機(jī)生成易于記憶的密碼

    這篇文章主要介紹了php實(shí)現(xiàn)隨機(jī)生成易于記憶的密碼,實(shí)例分析了php生成隨機(jī)密碼的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • php反射類ReflectionClass用法分析

    php反射類ReflectionClass用法分析

    這篇文章主要介紹了php反射類ReflectionClass用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了php反射類的概念、功能與具體使用方法,需要的朋友可以參考下
    2016-05-05
  • php簡(jiǎn)單統(tǒng)計(jì)字符串單詞數(shù)量的方法

    php簡(jiǎn)單統(tǒng)計(jì)字符串單詞數(shù)量的方法

    這篇文章主要介紹了php簡(jiǎn)單統(tǒng)計(jì)字符串單詞數(shù)量的方法,涉及php字符串分割與數(shù)組統(tǒng)計(jì)的相關(guān)技巧,需要的朋友可以參考下
    2015-06-06
  • php 數(shù)組使用詳解 推薦

    php 數(shù)組使用詳解 推薦

    對(duì)于網(wǎng)頁(yè)編程來(lái)說(shuō),最重要的就是存取和讀寫數(shù)據(jù)了。存儲(chǔ)方式可能有很多種,可以是字符串、數(shù)組、文件的形式等,今天學(xué)習(xí)了數(shù)組,可以說(shuō)是PHP的數(shù)據(jù)應(yīng)用中較重要的一種方式。
    2011-06-06
  • PHP高并發(fā)和大流量解決方案整理

    PHP高并發(fā)和大流量解決方案整理

    在本篇文章里小編給大家分享的是一篇關(guān)于PHP高并發(fā)和大流量解決方案內(nèi)容,有興趣的朋友們可以參考下。
    2019-12-12
  • php提取數(shù)字拼接數(shù)組的具體操作

    php提取數(shù)字拼接數(shù)組的具體操作

    在本篇文章里小編個(gè)大家整理了一篇關(guān)于php提取數(shù)字拼接數(shù)組的具體操作方法,有需要的朋友們可以跟著學(xué)習(xí)下。
    2021-08-08
  • PHP中余數(shù)、取余的妙用

    PHP中余數(shù)、取余的妙用

    這篇文章主要介紹了PHP中余數(shù)、取余的妙用,這個(gè)是在WEB開(kāi)發(fā)中一個(gè)經(jīng)常使用的小技巧,不管是在表格、ul、li或者是換行等HTML處理中,需要隔幾行換行,隔幾行加入ul或li的結(jié)束標(biāo)記等時(shí)候,特別的有用,需要的朋友可以參考下
    2015-06-06
  • php split漢字

    php split漢字

    php split漢字實(shí)現(xiàn)代碼。
    2009-06-06
  • PHP使用DirectoryIterator顯示下拉文件列表的方法

    PHP使用DirectoryIterator顯示下拉文件列表的方法

    這篇文章主要介紹了PHP使用DirectoryIterator顯示下拉文件列表的方法,涉及php使用DirectoryIterator操作文件的技巧,需要的朋友可以參考下
    2015-03-03
  • php操作redis的常見(jiàn)用法詳解

    php操作redis的常見(jiàn)用法詳解

    這篇文章主要為大家詳細(xì)介紹了php操作redis的常見(jiàn)用法的相關(guān)知識(shí),文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2023-11-11

最新評(píng)論