使用类

时间:2015-08-29 17:21:18

标签: php

我想打印:

if($this->year_info !== $year_now){

                $dataToPrint .= $this->year_info . "  " .$this->f_info. " FRST <br>";
             if ($this->month_info < $this->l_info+1){
                $dataToPrint .= $this->year_info . "  " .$this->l_info. " LAST <br>";
                $dataToPrint .= $this->year_info . "  " .$this->s_info. " SENM <br>";
            }
        }

如果年份发生变化:

Year
1
1
1
2
2
2

我想在第1年打印一次,在第2年打印一次。

我想检查一年是否会改变,但我仍然坚持这一部分。

首先,我正在执行一段时间,然后在里面发送给一个班级。

你知道我怎么检查吗?

     class printInfo {

    public $year_loop;   
    public $month_loop;
    public $f_loop;
    public $l_loop;
    public $s_loop;

    function __construct($year_loop, $month_loop, $f_loop, $l_loop, $s_loop) {
        $this->year_info = $year_loop;        
        $this->month_info = $month_loop;
        $this->f_info = $f_loop;
        $this->l_info = $l_loop;
        $this->s_info = $s_loop;
    }

    function getData($operation, $detail) {

        if ($operation !== null) {

            $year_now = $this->year_info;

            $dataToPrint = $this->year_info . "  " . $this->month_info . "  " . $operation . "<br>" . $detail . "<br>";


            if($this->year_info !== $year_now){

                    $dataToPrint .= $this->year_info . "  " .$this->f_info. " FRST <br>";
                 if ($this->month_info < $this->l_info+1){
                    $dataToPrint .= $this->year_info . "  " .$this->l_info. " LAST <br>";
                    $dataToPrint .= $this->year_info . "  " .$this->s_info. " SENM <br>";
                }
            }
            return $dataToPrint;


        }
    }
}

while ($rows = mysql_fetch_assoc($result)) {

    $pon = $rows["cop"];    
    $printInfo = new printInfo($rows["year"], $rows["month"], $rows["cf"], $rows["cl"], $rows["cs"]);

    if ($pon !== $pob) {
        echo $printInfo->getData($pon, $rows["cdp"]);
    }
    echo $printInfo->getData($rows["coi"], $rows["cdi"]);
    echo $printInfo->getData($rows["coh"], $rows["cdh"]);
    echo $printInfo->getData($rows["cof"], $rows["cdf"]);

    $pob = $rows["cop"];   
    $year_before = $rows["year"];
}

0 个答案:

没有答案