时间:2021-07-01 10:21:17 帮助过:25人阅读
前面已经写过如果只做动态柱状图的情况,其实原理还是很简单的。因为昨天下午有新的需求,今天上午又修改了一番,并将数据根据编号不同分割显示在表中。
下面把代码粘出来,方便以后自己查看,思路只是一时的火花,今天我想出来这么做,不一定下次还能想得到,也不用费劲的去想,所以写成笔记是比较好的形式。
<?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__))) . '/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);
// 查询每个人通过审核的情况:
$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);
?>
近一个月总的情况
|
<?php echo $d[0]?> |
<?php echo $d3[0]?> "> |
<?php echo $d4[0]?> "> |
<?php echo $d2[0]?> "> |
总计 |
一审通过 |
二审通过 |
审核通过 |
| 产品开发编号 | "; $trStr_total_score = "||||
|---|---|---|---|---|
| 总分 | "; $trStr_total_number = "||||
| 总数量 | "; $trStr_average_score = "||||
| 平均分 | "; $resultStr = ""; foreach ($newRow as $key => $value) { // echo $key."=>".$value."" . $value2 . " | "; // 表头 } elseif ($key2 == 'total_score') { $value2 = sprintf("%.2f", $value2); //保留2位小数 $trStr_total_score .= "" . $value2 . " | "; $x += $value2; } elseif ($key2 == 'total_number') { $trStr_total_number .= "" . $value2 . " | "; $x /= $value2; } } $x = sprintf("%.2f",$x); $trStr_average_score .= "" . $x . " | "; } echo "
数据库方便就不弄了,其实,根据查询的表名和字段名,是很容易建一个测试的数据表的。关键是思路,无论怎么变,思路是关键。
为了更加方便的了解代码的效果,截个图吧

希望本文所述对大家的php程序设计有所帮助。