Good day! I have this question. How can I optimize the code presented below (I hope for a weak court, since I’m not engaged in a long time) code.
Made a site on Codeigniter that was required. Print the data from 2 tables (yes, the tables are not brought to 3nf, because the base was made before me and I was not given time to work out the base properly, but only want to increase the functionality). And upon request, 4 mandatory fields were made, which are always displayed and 26 optional, which were made by checkboxes (this is terrible) and now I get this code on the output.
<tr> <th> Станция назначение </th> <th> Станция операции </th> <th> Номер вагона </th> <th> Дата </th> <th> Время </th> <? if($op == "yes"):?> <th> ОП </th> <? endif;?> <? if($dpr == "yes"):?> <th> ДПР </th> <? endif;?> <? if($inpoezd == "yes"):?> <th> Индекс поезда </th> <? endif;?> <? if($gruz == "yes"):?>
etc.
<? foreach ($disla as $item):?> <? $x = $item->naznachenie; $q = $item->operation; for($i=0; $i< count($item->naznachenie); $i++) { if ($x != $y) { echo "<tr><td>".$x."</td><td></td></tr>"; $t = true; $y = $x; } else { $t = false; } } for ($i=0; $i< count($item->operation); $i++) { if ($q != $w or $t == true) { echo "<tr><td></td><td>".$q."</td></tr>"; $w = $q; } } ?> <tr> <td></td> <td></td> <td><a href="#" style='text-decoration: none;' id="<?=$item->number_vagona?>" onclick="TellId(this)"><?=$item->number_vagona?></a></td> <? $date_out = date("dmY", strtotime($item->date)); if(strtotime($date11) == strtotime($date_out) or strtotime($date1) == strtotime($date_out) and ($item->time) > $time) { echo "<td style='color: #3caa3c;'><strong>".$date_out."</strong></td>"; } elseif(strtotime($date_out) <= strtotime($date5) and strtotime($date_out) > strtotime($date10)) { echo "<td style='color: orange;'><strong>".$date_out."</strong></td>"; } elseif(strtotime($date_out) <= strtotime($date10)) { echo "<td style='color: red;'><strong>".$date_out."</strong></td>"; } else echo "<td><strong>".$date_out."<strong></td>"; ?> <td><?=$item->time ?></td> <? if($op == "yes"):?> <td><?=$item->op ?></td> <? endif;?> <? if($comment == "yes"):?> <td><input onchange="uodate(<?=$item->number_vagona ?>,'comment',this)" type="text" value="<?=$item->comment ?>" id="noborder"/></td> <? endif;?>
when displaying, the first two columns are compared, the date is displayed in color.
I of course cut it down very much, imagine 40 columns for the choice of the user. everything seems to be working, but the speed of work is just awful. I understand that in many ways I did wrong. Please write remarks where what can be done better? Thank you very much in advance!