Home  >  Article  >  php教程  >  PHP动态柱状图改进版

PHP动态柱状图改进版

WBOY
WBOYOriginal
2016-06-06 19:55:09977browse

前面已经写过如果只做动态柱状图,其实原理还是很简单的。今天,因为昨天下午有新的需求,今天上午又修改了一番,并将数据根据编号不同分割显示在表中。 下面把代码粘出来,方便以后自己查看,思路只是一时的火花,今天我想出来这么做,不一定下次还能想得到

    前面已经写过如果只做动态柱状图,其实原理还是很简单的。今天,因为昨天下午有新的需求,今天上午又修改了一番,并将数据根据编号不同分割显示在表中。

   下面把代码粘出来,方便以后自己查看,思路只是一时的火花,今天我想出来这么做,不一定下次还能想得到,也不用费劲的去想,所以写成笔记是比较好的形式。

  

<?php // 计算上一个月的今天
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__))) . &#39;/config.php&#39;;
$endDate = date(&#39;Y-m-d&#39;);
$date = strtotime($endDate);
$beginDate = last_month_today($date);

$sql = &#39;select count(*) from newpro where p_date>\'' . $beginDate . '\' and p_datequery($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);

// 查询每个人通过审核的情况:
$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);
?>


<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>


	<h3 align="center">近一个月总的情况</h3>
	

总计

一审通过

二审通过

审核通过

近一个月每个人的情况

产品开发编号"; $trStr_total_score = ""; $trStr_total_number = ""; $trStr_average_score = ""; $resultStr = ""; foreach ($newRow as $key => $value) { // echo $key."=>".$value."
"; $x = 0; foreach ($value as $key2 => $value2) { // echo $key2 . "=>" . $value2 . "
"; if ($key2 == 'd_m') { $thStr .= ""; // 表头 } elseif ($key2 == 'total_score') { $value2 = sprintf("%.2f", $value2); //保留2位小数 $trStr_total_score .= ""; $x += $value2; } elseif ($key2 == 'total_number') { $trStr_total_number .= ""; $x /= $value2; } } $x = sprintf("%.2f",$x); $trStr_average_score .= ""; } echo "
每个人的完成情况如下表:
总分
总数量
平均分" . $value2 . "" . $value2 . "" . $value2 . "" . $x . "
"; echo $thStr; echo $trStr_total_number . ""; echo $trStr_total_score . ""; echo $trStr_average_score . ""; echo "
"; echo "

"; } ?> 数据库方便就不弄了,其实,根据查询的表名和字段名,是很容易建一个测试的数据表的。关键是思路,无论怎么变,思路是关键。

       为了更加方便的了解代码的效果,截个图吧

PHP动态柱状图改进版


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