Home > Article > Backend Development > How to implement dynamic histogram in PHP_PHP tutorial
This article mainly introduces the PHP dynamic histogram implementation method. It analyzes the techniques of PHP combined with HTML elements to implement dynamic histogram. It is very useful. Practical value, friends in need can refer to it
The example in this article describes the implementation method of dynamic histogram in PHP. Share it with everyone for your reference. The specific analysis is as follows:
1. Demand
Query the total number of data items and the number of approved items in the last month, and make a histogram
2. Implementation code:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
//Calculate today’s day of the previous month 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); } ?>
include dirname(dirname(dirname(__FILE__))).'/config.php'; $endDate = date('Y-m-d'); $date = strtotime($endDate); $beginDate= last_month_today($date);
//Query the total number of data items in the last month $sql = 'select count(*) from newpro where p_date>''.$beginDate.'' and p_date<''.$endDate.'''; //$sql = "select count(*) from newpro where p_date>'$beginDate' and p_date <'$endDate'";//This statement can also be used $d = db()->query($sql)->fetch(PDO::FETCH_NUM); //echo "Total number of data items:".$d[0];
//Query the number of data items that have passed the review $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); //echo "Number of data items passed the review:".$d2[0];
//Query the number of items that have passed the review $sql3=$sql.' and is_pa_check_first=1'; $d3 = db()->query($sql3)->fetch(PDO::FETCH_NUM);
//Query the number of items that passed the second review $sql4=$sql.' and is_pa_check_first=1 and is_pa_check_second=1'; $d4 = db()->query($sql4)->fetch(PDO::FETCH_NUM); ?>
table{ cellpadding:0px; cellspacing:0px; } p{ padding:0px; margin:0px; } div{ background-color:#669900; width:50px; } #div1{ height:200px; }
|
3.效果图如下所示:
希望本文所述对大家的php程序设计有所帮助。