There is a finished table that should be displayed by date, the same names remain in the "NAME" column, but subsequent columns should be filled in via a two-dimensional array by date. According to the principle, if I chose today's date, then I was given a column with names and (if this month has 30 days) for each column some kind of any figure for example, but if I choose a date with 28 days, then the same names are also filled already 28 columns are filled through a two-dimensional array.

DATE SELECTION

<input style=" width:200px; height:27px; position:absolute; left:50%;top:15%;z-index:2; margin-left:-130px; " id="monthToday" name="dateList" type="month"> <script> document.getElementById('monthToday').valueAsDate = new Date(); </script> <input style="margin:auto; width:40px; height:30px; position:absolute; left:50%;top:15%;z-index:2; margin-left:90px; " type="submit" value="ok"> 

FUNCTIONAL

 <?php if(isset($_POST['dateList'])){ $inp_inf = $_POST['dateList']; }else{ $inp_inf = date('Ym-d'); } $date = new DateTime($inp_inf); $car_year = $date->format('Y') ; // 2018 $car_month = $date->format('m') ; // 1-12 текущий месяц $allcells = "<tr><td style='margin:auto;height:50px; font-weight:bold' colspan='32'align='center'>ДАТА ТАБЛИЦЫ $inp_inf </td></tr>"; $tablheader = "$allcells<tr><td style='width:200px;font-weight:bold; vertical-align: top'>Имя</td>"; // построение таблицы $i = 0; $w = "-" ; $day_w = 0 ; while($i++ < $date->format('t')) { $car_data = $car_year."-".$car_month."-".$i." 01:01:01" ; $tmp_data = strtotime($car_data); $day_w = date("N",$tmp_data); if($day_w==1) {$w = "Пн" ;} if($day_w==2) {$w = "Вт" ;} if($day_w==3) {$w = "Ср" ;} if($day_w==4) {$w = "Чт" ;} if($day_w==5) {$w = "Пт" ;} if($day_w==6) {$w = "Сб" ;} if($day_w==7) {$w = "Вс" ;} $tablheader = $tablheader."<td style='width:200px; vertical-align: top'>".$i." / ".$w."</td>" ; } // ЗАПИСЬ В ДВУХМЕРНОМ МАССИВЕ НАЧАЛО---------------------------------------------------------------------------------------------------------------------------- $row = 3;// количество строк $col = $i + 1;// кол. столбиков $n [0] = "Андрей"; $n [1] = "Олег"; $n [2] = "Володя"; $n [3] = "Дима"; $tablheader = $tablheader."</tr>"; echo $tablheader; ?> 
  • 2
    300 questions at each stage, for each line of code. You stopped thinking, you advised you to at least cope with this task yourself. - Manitikyl
  • Copy + paste ... - ishidex2

1 answer 1

Everything, if someone needs to be able to use, all that was needed - DONE)

 if(isset($_POST['dateList'])){ $inp_inf = $_POST['dateList']; }else{ $inp_inf = date('Ym-d'); } $date = new DateTime($inp_inf); $car_year = $date->format('Y') ; // 2018 $car_month = $date->format('m') ; // 1-12 текущий месяц $car_days = $date->format('t') ; // $allcells = "<tr><td style='margin:auto;height:50px; font-weight:bold' colspan='32'align='center'>ДАТА ТАБЛИЦЫ $inp_inf </td></tr>"; $tablheader = "$allcells<tr><td style='width:200px;font-weight:bold; vertical-align: top'>Имя</td>"; // построение таблицы $i = 0; $w = "-" ; $day_w = 0 ; while($i++ < $car_days) { $car_data = $car_year."-".$car_month."-".$i." 01:01:01" ; $tmp_data = strtotime($car_data); $day_w = date("N",$tmp_data); if($day_w==1) {$w = "Пн" ;} if($day_w==2) {$w = "Вт" ;} if($day_w==3) {$w = "Ср" ;} if($day_w==4) {$w = "Чт" ;} if($day_w==5) {$w = "Пт" ;} if($day_w==6) {$w = "Сб" ;} if($day_w==7) {$w = "Вс" ;} $tablheader = $tablheader."<td style='width:200px; vertical-align: top'>".$i." / ".$w."</td>" ; } $tablheader = $tablheader."</tr>"; $max_str = 5 ; $name[0] = "Ivanov1" ; $name[1] = "Ivanov2" ; $name[2] = "Ivanov3" ; $name[3] = "Ivanov4" ; $name[4] = "Ivanov5" ; $name[5] = "Ivanov6" ; for ($str=0;$str<$max_str;$str++){ $tablheader = $tablheader."<tr>"; $tablheader = $tablheader."<td>".$name[$str]."</td>"; $hour[0] = 21 ; $hour[1] = 23 ; $hour[2] = 33 ; $hour[3] = 12 ; $hour[4] = 13 ; $hour[5] = 34 ; $hour[6] = 23 ; $hour[7] = 12 ; $hour[8] = 23 ; $hour[9] = 34 ; $hour[10] = 43 ; $hour[11] = 34 ; $hour[12] = 56 ; $hour[13] = 45 ; $hour[14] = 34 ; $hour[15] = 23 ; $hour[16] = 65 ; $hour[17] = 44 ; $hour[18] = 3 ; $hour[19] = 45 ; $hour[20] = 34 ; $hour[21] = 23 ; $hour[22] = 45 ; $hour[23] = 43 ; $hour[24] = 23 ; $hour[25] = 11 ; $hour[26] = 22 ; $hour[27] = 33 ; $hour[28] = 44 ; $hour[29] = 55 ; $hour[30] = 66 ; for ($day=0;$day<$car_days;$day++){ $tablheader = $tablheader."<td>".$hour[$day]."</td>"; } $tablheader = $tablheader."</tr>"; } echo $tablheader; ?>