为每个不同的单元格创建不同的ID

时间:2016-02-24 05:00:35

标签: php class

我想为每个不同的单元格创建不同的id和值以供出席。

 public function show() {
    $year  == null;
    $month == null;

    if(null==$year&&isset($_GET['year'])){
        $year = $_GET['year'];

    }else if(null==$year){
        $year = date("Y",time());  
    }          

    if(null==$month&&isset($_GET['month'])){
        $month = $_GET['month'];
    }else if(null==$month){
        $month = date("m",time());
    }                  

    $this->currentYear=$year;
    $this->currentMonth=$month;
    $this->daysInMonth=$this->_daysInMonth($month,$year);  

    $content='<div class="row row-centered"><div class="col-xs-6 col-centered">'.
                    $this->_createNavi().
                    '</div></div>'.
                            '<table class="table-bordered"><tr><th>Student Name</th>
                            <th>M</th><th>Tu</th><th>W</th><th>Th</th><th>F</th><th>Sa</th><th>Su</th>
                            <th>M</th><th>Tu</th><th>W</th><th>Th</th><th>F</th><th>Sa</th><th>Su</th>
                            <th>M</th><th>Tu</th><th>W</th><th>Th</th><th>F</th><th>Sa</th><th>Su</th>
                            <th>M</th><th>Tu</th><th>W</th><th>Th</th><th>F</th><th>Sa</th><th>Su</th>
                            <th>M</th><th>Tu</th><th>W</th><th>Th</th><th>F</th><th>Sa</th><th>Su</th>
                            <th>M</th><th>Tu</th><th>W</th><th>Total</th>
                            </tr>';  
                            //$content.='<div class="clear"></div>';     
                            $content.='<tr><td>ID</td>';    

                            $weeksInMonth = $this->_weeksInMonth($month,$year);
                            // Create weeks in a month
                            for( $i=0; $i<$weeksInMonth; $i++ ){

                                //Create days in a week
                                for($j=1;$j<=7;$j++){
                                    $content.=$this->_showDay($i*7+$j);
                                }
                            }

                            $content.='</tr>';
                            $info="SELECT id,user_name FROM std_master";
                            $final=mysql_query($info);
                            while($row=mysql_fetch_object($final)){
                             $content.='<tr><td>'.$row->user_name.$row->id.'</td>';    

                            $weeksInMonth = $this->_weeksInMonth($month,$year);
                            // Create weeks in a month
                            for( $k=0; $k<$weeksInMonth; $k++ ){

                                //Create days in a week
                                for($l=1;$l<=7;$l++){

                                    $content.=$this->_showCheck($k*7+$l , $row->id);
                                }
                            }
                             }
                            $content.='</tr>';


                            //$content.='<div class="clear"></div>';     

                   // $content.='</div>';

    //$content.='</table>';
    return $content;   

}

/********************* PRIVATE **********************/ 
/**
* create the li element for ul
*/
private function _showDay($cellNumber){

    if($this->currentDay==0){
        $firstDayOfTheWeek = date('N',strtotime($this->currentYear.'-'.$this->currentMonth.'-01'));
        if(intval($cellNumber) == intval($firstDayOfTheWeek)){
            $this->currentDay=1;
        }
    }

    if( ($this->currentDay!=0)&&($this->currentDay<=$this->daysInMonth) ){
        $this->currentDate = date('Y-m-d',strtotime($this->currentYear.'-'.$this->currentMonth.'-'.($this->currentDay)));
        $cellContent = $this->currentDay; 
        $this->currentDay++;   
    }else{
        $this->currentDate =null;
        $cellContent=null;
    }

    return '<td  style="border-bottom: 1px solid #000000" align="center" valign=bottom bgcolor="#EEDFD8" sdval="41883" sdnum="1033;0;D"><font size=1 value="td-'.$this->currentDate.'" id="td-'.$this->currentDate.'" class="'.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
            ($cellContent==null?'mask':'').'">'.$cellContent.'</font></td>';

}

private function _showCheck($cellNumber,$id) {
    if($this->currentDays==0) {
        $firstDayOfTheWeeks = date('N',strtotime($this->currentYears.'-'.$this->currentMonths.'-01'));
        if(intval($cellNumbers) == intval($firstDayOfTheWeeks)) {
            $this->currentDays=1;
        }
    }

    if(($this->currentDays!=0)&&($this->currentDays<=$this->daysInMonths)) {
        $this->currentDates = date('Y-m-d',strtotime($this->currentYears.'-'.$this->currentMonths.'-'.($this->currentDays)));
        $cellContents = $this->currentDays; 
        $this->currentDays++;   
    } else {
        $this->currentDates =null;
        $cellContents=null;
    }


    return '<td  style="border-bottom: 1px solid #000000" align="center" valign=bottom bgcolor="#EEDFD8" sdval="41883" sdnum="1033;0;D"><input type="checkbox" size=1 value="'.$id.'-'.$this->currentDates.'" id="'.$id.'-'.$this->currentDates.'" class="'.($cellNumber%7==1?' start ':($cellNumber%7==0?' end ':' ')).
            ($cellContents==null?'mask':'').'">'.$cellContents.'</td>';

}

我希望为每个不同的单元格创建不同的ID。

Screenshot of checkboxes

1 个答案:

答案 0 :(得分:0)

而不是

id="'.$id.'-'.$this->currentDates.'"

尝试类似:

id="td_'.$cellNumber.'"

使用字母数字而非数字启动它,并使用已识别单元格的cellNumber