亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

PHP實(shí)現(xiàn)動(dòng)態(tài)柱狀圖改進(jìn)版

 更新時(shí)間:2015年03月30日 09:21:19   作者:詩(shī)未冷  
這篇文章主要介紹了PHP實(shí)現(xiàn)動(dòng)態(tài)柱狀圖改進(jìn)版,是在前面所述實(shí)現(xiàn)柱狀圖的基礎(chǔ)上進(jìn)行的改進(jìn),具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例分析了PHP實(shí)現(xiàn)動(dòng)態(tài)柱狀圖的改進(jìn)版。分享給大家供大家參考。具體分析如下:

前面已經(jīng)寫(xiě)過(guò)如果只做動(dòng)態(tài)柱狀圖的情況,其實(shí)原理還是很簡(jiǎn)單的。因?yàn)樽蛱煜挛缬行碌男枨?,今天上午又修改了一番,并將?shù)據(jù)根據(jù)編號(hào)不同分割顯示在表中。

下面把代碼粘出來(lái),方便以后自己查看,思路只是一時(shí)的火花,今天我想出來(lái)這么做,不一定下次還能想得到,也不用費(fèi)勁的去想,所以寫(xiě)成筆記是比較好的形式。

<!DOCTYPE html> 
<?php 
// 計(jì)算上一個(gè)月的今天 
function last_month_today($time) 
{ 
  $last_month_time = mktime(date("G", $time), date("i", $time), date("s", $time), date("n", $time), 0, date("Y", $time)); 
  $last_month_t = date("t", $last_month_time); 
  if ($last_month_t < date("j", $time)) { 
  return date("Y-m-t H:i:s", $last_month_time); 
  } 
  return date(date("Y-m", $last_month_time) . "-d", $time); 
} 
?> 
<?php 
include dirname(dirname(dirname(__FILE__))) . '/config.php'; 
$endDate = date('Y-m-d'); 
$date = strtotime($endDate); 
$beginDate = last_month_today($date); 
$sql = 'select count(*) from newpro where p_date>\'' . $beginDate . '\' and p_date<\'' . $endDate . '\''; 
$d = db()->query($sql)->fetch(PDO::FETCH_NUM); 
$sql2 = $sql . ' and is_pa_check_first=1 and is_pa_check_second=1 and is_pa_check_third=1'; 
$d2 = db()->query($sql2)->fetch(PDO::FETCH_NUM); 
$sql3 = $sql . ' and is_pa_check_first=1'; 
$d3 = db()->query($sql3)->fetch(PDO::FETCH_NUM); 
$sql4 = $sql . ' and is_pa_check_first=1 and is_pa_check_second=1'; 
$d4 = db()->query($sql4)->fetch(PDO::FETCH_NUM); 
// 查詢(xún)每個(gè)人通過(guò)審核的情況: 
$sqlab = 'select d_m,sum(sroce) as total_score,count(d_m) as total_number 
from newpro 
  where is_pa_check_first=1 
  and is_pa_check_second=1 
  and is_pa_check_third =1 
group by d_m'; 
$row = db()->query($sqlab)->fetchAll(PDO::FETCH_ASSOC); 
?> 
<html> 
<head> 
<meta charset="utf-8" /> 
<style> 
div { 
  background-color: #669900; 
  width: 50px; 
} 
#div1 { 
  height: 200px; 
} 
#table td { 
} 
</style> 
<script type="text/javascript" src="../../../js/jquery-1.7.2.min.js"></script> 
</head> 
<body> 
  <h3 align="center">近一個(gè)月總的情況</h3> 
  <table border="0" align="center" id="table1"> 
  <caption> 
     <?php echo "時(shí)間:".$beginDate."至".$endDate?> 
     </caption> 
  <tr align="center" valign="bottom"> 
    <td> 
    <p><?php echo $d[0]?></p> 
    <div id="div1"></div> 
    </td> 
    <td> 
    <p><?php echo $d3[0]?></p> 
    <div style="height:<?php $str=floor(($d3[0]/$d[0])*200); echo $str.'px'?>"></div> 
    </td> 
    <td> 
    <p><?php echo $d4[0]?></p> 
    <div style="height:<?php $str=floor(($d4[0]/$d[0])*200); echo $str.'px'?>"></div> 
    </td> 
    <td> 
    <p><?php echo $d2[0]?></p> 
    <div style="height:<?php $str=floor(($d2[0]/$d[0])*200); echo $str.'px'?>"></div> 
    </td> 
  </tr>
  <tr align="center" valign="top"> 
    <td><p>總計(jì)</p></td> 
    <td><p>一審?fù)ㄟ^(guò)</p></td> 
    <td><p>二審?fù)ㄟ^(guò)</p></td> 
    <td><p>審核通過(guò)</p></td> 
  </tr> 
  </table> 
  <h3 align="center">近一個(gè)月每個(gè)人的情況</h3> 
  <table border="0" width="100%"> 
  <caption>每個(gè)人的完成情況如下表:</caption>
  <!-- 因?yàn)榭偟牧袛?shù)比較長(zhǎng),如果顯示在一個(gè)表格中,數(shù)據(jù)會(huì)很擁擠,多的話(huà)根本就看不清楚。 
     所以需要將數(shù)據(jù)進(jìn)行分割,根據(jù)長(zhǎng)度進(jìn)行動(dòng)態(tài)的分割,顯示在多張表中。 
   --> 
    <?php 
    $arr = array_chunk($row,2,false);//2表示分割的單位長(zhǎng)度,false表示索引從0開(kāi)始 
    foreach($arr as $newRow){ 
      $thStr = "<th style='background-color:#669900' width='110px' height='30px'>產(chǎn)品開(kāi)發(fā)編號(hào)</th>"; 
      $trStr_total_score = "<tr align='center' style='background-color:silver' height='25px'><td>總分</td>"; 
      $trStr_total_number = "<tr align='center' style='background-color:silver' height='25px'><td>總數(shù)量</td>"; 
      $trStr_average_score = "<tr align='center' style='background-color:silver' height='25px'><td>平均分</td>"; 
      $resultStr = ""; 
      foreach ($newRow as $key => $value) { 
      // echo $key."=>".$value."<br/>"; 
      $x = 0; 
      foreach ($value as $key2 => $value2) { 
        // echo $key2 . "=>" . $value2 . "<br/>"; 
        if ($key2 == 'd_m') { 
        $thStr .= "<th style='background-color:#669900'>" . $value2 . "</th>"; // 表頭 
        } elseif ($key2 == 'total_score') { 
        $value2 = sprintf("%.2f", $value2); //保留2位小數(shù) 
        $trStr_total_score .= "<td>" . $value2 . "</td>"; 
        $x += $value2; 
        } elseif ($key2 == 'total_number') { 
 
        $trStr_total_number .= "<td>" . $value2 . "</td>"; 
        $x /= $value2; 
        } 
      } 
      $x = sprintf("%.2f",$x); 
      $trStr_average_score .= "<td>" . $x . "</td>"; 
      } 
      echo "<table border='0' width='100%'>"; 
      echo $thStr; 
      echo $trStr_total_number . "</tr>"; 
      echo $trStr_total_score . "</tr>"; 
      echo $trStr_average_score . "</tr>"; 
      echo "</table>"; 
      echo "<p height='150px'></p>"; 
    } 
    ?> 
  </table> 
</body> 
</html>

數(shù)據(jù)庫(kù)方便就不弄了,其實(shí),根據(jù)查詢(xún)的表名和字段名,是很容易建一個(gè)測(cè)試的數(shù)據(jù)表的。關(guān)鍵是思路,無(wú)論怎么變,思路是關(guān)鍵。

為了更加方便的了解代碼的效果,截個(gè)圖吧

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

相關(guān)文章

最新評(píng)論