Good afternoon, dear users. Please help in the situation.
I am writing a page for entering information about employee schedules. The number of tables depends on the number of sectors in which employees are registered. The number of entries in each table corresponds to the number of employees in the sector. The number of columns in the table depends on the month, i.e. how many days, so many columns.
On the page in the pop-up window, information on a specific day is entered, transferred to the handler using AJAX, data is written to the database (there are no problems here), the problem is that it is necessary each time the page is refreshed to color the table cell with a certain color depending on the selected parameters i.e. I should add an id to the td with the class .day in the format: TABLE_NUMER_YE_MODIC_DATE and then on a specific id that contains the value I need, I will color the cells using JQuery.
Please help in solving the problem. Code for dynamic table rendering:
//Выбор всех операторов, сортировка по рабочему сектору $sql = "SELECT t1.tabNo, t1.sector, t2.otdelname, t1.name, t3.date, t3.cause FROM operators as t1 JOIN otdel as t2 on t1.napravlenie = t2.id LEFT JOIN day_detail as t3 on t1.tabNo= t3.tabNo WHERE rol = '1' AND admin = 0 ORDER BY sector, name ASC "; $query = mysqli_query($connect,$sql); //Выполнение запроса в БД; //Результат выполнения загоняем в массив peopInfo $i=0; $j=0; $sector1 = -1; $cols = $countDay; // количество столбцов, td - Определяется динамически, зависит от месяца (сколько дней, столько столбцов) while ($auxiliaryArr = mysqli_fetch_assoc($query)) { //массив peopleInfo содержит данные: табельный номер оператора, имя оператора, № сектора, имя сектора, дату по которой вносится информация, причину изменения записи $peopleInfo[$i]['tabNo'] = $auxiliaryArr['tabNo']; $peopleInfo[$i]['name'] = $auxiliaryArr['name']; $peopleInfo[$i]['sector'] = $auxiliaryArr['sector']; $peopleInfo[$i]['otdel'] = $auxiliaryArr['otdel']; $peopleInfo[$i]['date'] = $auxiliaryArr['date']; $peopleInfo[$i]['cause'] = $auxiliaryArr['cause']; if ($auxiliaryArr['sector'] != $sector1) { if ($i!=0) { echo '</table>'; } echo '<table class = "tableEmployee" ; <colgroup> <col width = "400px"; > </colgroup>'; echo "<br>"; echo '<caption id="sector";> '.$peopleInfo[$j]['otdel'].' </caption>'; echo '<tr> <td id="fio"; rowspan = "2";> ФИО </td> <td id="tabNo"; rowspan="2";> Табельный номер </td> <td id="day"; colspan="31"; style="background:#fffff";> Дата </td> </tr>'; //Выводим в таблицу строку с датой (прим.: 01, 02, 03) $dateArr = Array(); //Вспомогательный массив $d = 1; //Нумерация дня с 1-го числа каждого месяца while ($d <= $countDay): $dateArr[$d]['day'] = $d; echo '<td id="chislo"> '.htmlspecialchars($dateArr[$d]['day']).' </td> '; $sector1= $auxiliaryArr['sector']; //присвоение "пустой" переменной значения id сектора из массива $auxiliaryArr $d++; endwhile; //цикл динамичной отрисовки таблиц } echo "<tr>"; for ($td=1;$td<$cols+2;$td++) { $id[$j] = strtoupper($peopleInfo[$j]['tabNo']); if($td == 1) { echo "<th class='fio'; title='Внести информацию по сотруднику'>".$peopleInfo[$j]['name']."</th>"; echo "<th class='login';> ".strtoupper($peopleInfo[$j]['tabNo'])." </th>"; } else { echo "<td class='day' >".substr($peopleInfo[$j]['cause'],0,1)."</td>"; } } echo "</tr>"; $i++; $j++; } echo "</table>"; Scrolling through the months and, accordingly, changing the number of columns is done using a function in the same file:
<?PHP $countDay = my_calendar(array(date("Ymd"))); function my_calendar($fill=array()){ $month_names=array("Январь","Февраль","Март","Апрель","Май","Июнь","Июль","Август","Сентябрь","Октябрь","Ноябрь","Декабрь"); if (isset($_GET['y'])) $y=$_GET['y']; if (isset($_GET['m'])) $m=$_GET['m']; if (!isset($y) OR $y < 1970 OR $y > 2037) $y=date("Y"); if (!isset($m) OR $m < 1 OR $m > 12) $m=date("m"); $month_stamp=mktime(0,0,0,$m,1,$y); $prev=date('?\m=m&\y=Y',mktime (0,0,0,$m-1,1,$y)); $next=date('?\m=m&\y=Y',mktime (0,0,0,$m+1,1,$y)); $i=0; ?> <table class="tableMonth"> <tr> <td> <table> <tr> <td align="left"><a href="<? echo $prev . " " ?>"><<< </a></td> <td id="month_year" align="center"><? echo $m.".".$y ?></td> <td align="right"><a href="<? echo $next ?>"> >>></a></td> </tr> </table> </td> </tr> </table> <?PHP echo '<hr>'; if ($m == 4 || $m == 6 || $m == 9 || $m == 11){ $countdays = 30; return $countdays; } elseif ($m == 2){ $countdays = 28; return $countdays; } else { $countdays = 31; return $countdays; } } ?>