The following code corresponds to a cycle that fills a calendar made with HTML. In this case, the events obtained by dates from the DB are shown. Those dates are doubled and try to fix it with an if but it just stops me from repeating the last event. For example I have an event for October 12 and another for the 16, with the if I put the 16 does not repeat it twice, but the 12 if it repeats.
$eventos = DAOEvento :: consultarTodos(Conexion :: obtenerConexion());
for ($dia = 1; $dia <= $contador_dias; $dia++, $texto++) {
$fecha = $ym . '-' . $dia;
if ($hoy == $fecha) {
$semana .= '<td class="hoy">' . '<a href="'.$ruta_elegida."?fecha=".$fecha.'&f=true">'.$dia.'</a>';
} else {//START TO VERIFY IF THERE IS AN EVENT IN THE DB WITH THE DATE foreach ($eventos as $evento) {//ONLY SHOWS A FORM WITH THE INFORMATION OF THE LAST EVENT $fecha_obtenida = $evento -> obtenerCierre();
list($fecha_cierre, $hora_cierre) = explode(' ', $fecha_obtenida);
$fecha_recuperada = $evento -> obtenerInicio();
list($fecha_inicio, $hora_inicio) = explode(' ', $fecha_recuperada);
if ($fecha_inicio == $fecha) {//IF THE DATE OF THE EVENT MATCHES WITH THE DAY THEN MARK IT WITH THE CLASS EVENT $semana .= '<td class="evento">' . '<a href="'.$ruta_elegida."?fecha=".$fecha.'&f=true&e=true">'.$dia.'</a>';
}
}
if ($fecha !== $fecha_inicio) {//THIS IF SOLVES THE EXAMPLE YOU MENTION BEFORE $semana .= '<td>' . '<a href="'.$ruta_elegida."?fecha=".$fecha.'&f=true">'.$dia.'</a>';
}
}
$semana .= '</td>';
// End of the week OR End of the month
if ($texto % 7 == 6 || $dia == $contador_dias) {
if ($dia == $contador_dias) {
// Add empty cell
$semana .= str_repeat('<td></td>', 6 - ($texto % 7));
}
$semanas[] = '<tr>' . $semana . '</tr>';
// Prepare for new week
$semana = '';
}
}
It is worth mentioning that I tried to change the if of the "solution" to a while or switch, but told me that the bytes were over or something like that. Additionally, when I click on the day that has an event, it only returns the last event, that is, when I click on day 12, it returns the information of the event on the 16th. I have tried changing the foreach for a for, but it deteriorates much more the structure of the calendar. I appreciate the contributions in advance to solve the problem.
Aucun commentaire:
Enregistrer un commentaire