PHP implementation Dynamic histogram improved version, PHP histogram improved version _php tutorial

Source: Internet
Author: User
Tags sprintf

PHP implementation Dynamic histogram improved version, PHP histogram improved version


In this paper, an improved version of dynamic histogram for PHP is analyzed. Share to everyone for your reference. The specific analysis is as follows:

It has been written that if only the dynamic histogram of the case, the principle is still very simple. Because there was a new demand yesterday afternoon, this morning modified again, and the data according to the number of different segmentation display in the table.

The following code to stick out, convenient to see themselves later, the idea is just a spark, today I want to come out to do so, not necessarily next time can also want to think, and do not have to worry about, so write notes is a better form.

 <?php//Calculates the Today's function Last_month_today ($time) {$last _month_time = mktime (Date ("G", $time), date ("I", $time) for the last one months,   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); $sql 2 = $sql. ' and Is_pa_check_first=1 and is_pa_check_second=1 and Is_pa_check_third=1 '; $d 2 = db ()->query ($sql 2)->fetch (pdo::fetch_num); $sql 3 = $sql. ' and Is_pa_check_first=1 '; $d 3 = db ()->query ($sql 3)->fetch (pdo::fetch_num); $sql 4 = $sql. ' And Is_pa_check_fiRst=1 and Is_pa_check_second=1 '; $d 4 = db ()->query ($sql 4)->fetch (pdo::fetch_num); Query everyone through auditing: $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);?>  
 
  
        

Total situation in the last one months

<?php echo "Time:". $beginDate. " to the. $endDate?>

<?php Echo $d [0]?>

<?php Echo $d 3[0]?>

">

<?php Echo $d 4[0]?>

">

<?php Echo $d 2[0]?>

">

Total

First Instance passed

Second-Instance Adoption

Audit through

The situation of everyone in the last one months



<?php $arr = Array_chunk ($row, 2,false),//2 represents the unit length of the split, false indicates that the index starts with 0 foreach ($arr as $newRow) {$thStr = " "; $trStr _total_score = " "; $trStr _total_number = " "; $trStr _average_score = " "; $RESULTSTR = ""; foreach ($newRow as $key = + $value) {//echo $key. " = ". $value."; $x = 0; foreach ($value as $key 2 = $value 2) {//Echo $key 2. "=". $value 2. ""; if ($key 2 = = ' D_m ') {$thStr. = " "; Table Header} elseif ($key 2 = = ' Total_score ') {$value 2 = sprintf ("%.2f", $value 2);//2 decimal places reserved $trStr _tota L_score. = " "; $x + = $value 2; } elseif ($key 2 = = ' Total_number ') {$trStr _total_number. = " "; $x/= $value 2; }} $x = sprintf ("%.2f", $x); $trStr _average_score. = " "; } echo "
the completion of each person is shown in the following table:
Product development number
Score
Total quantity
average score ". $value 2. "". $value 2. "". $value 2. "". $x. "
"; Echo $thStr; Echo $trStr _total_number. ""; Echo $trStr _total_score. ""; Echo $trStr _average_score. ""; echo "
"; echo "

"; }?>

The database is not easy to get, in fact, according to the query table name and field name, it is easy to build a test data table. The key is the idea, no matter how change, the idea is the key.

For a more convenient understanding of the effect of the code, cut a graph bar

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/976037.html www.bkjia.com true http://www.bkjia.com/PHPjc/976037.html techarticle PHP Implementation of dynamic histogram improved version, PHP histogram improved version of the text example analysis of PHP implementation of dynamic histogram of the improved version. Share to everyone for your reference. The specific analysis is as follows: the previous ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.