search
Homephp教程php手册PHP动态柱状图改进版

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

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

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

  

<?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 id="近一个月总的情况">近一个月总的情况</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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),