I have a dynamic input that checks the date the user selects and then returns the available hours for scheduling, however when the user selects the date of the day (data = hoje)
I would like the hours that have passed to be deleted from the input.
Example:
The date chosen is today and it is now 4:13 pm, my input should display
17:00 - 18:00 - 19:00 - 8:00 pm - 21:00 - 22:00 - 23:00
Follow the code:
<?php
session_start();
require_once('library.php');
$hoje = date('d/m/Y');
$amanha = date("d/m/Y", mktime(0,0,0,date("m"),(date("d")+1),date("Y")));
$damanha = date("d/m/Y", mktime(0,0,0,date("m"),(date("d")+2),date("Y")));
$predata = $_POST['predata'];
$sql = "SELECT Hora FROM tbl_agenda WHERE Data = '$predata'";
$atualizahoje = "UPDATE tbl_agenda SET Data='". $hoje ."' WHERE id=33";
$atualizaamanha = "UPDATE tbl_agenda SET Data='". $amanha ."' WHERE id=34";
$atualizadamanha = "UPDATE tbl_agenda SET Data='". $damanha ."' WHERE id=35";
$qr1 = mysql_query($atualizahoje) or die(mysql_error());
$qr2 = mysql_query($atualizaamanha) or die(mysql_error());
$qr3 = mysql_query($atualizadamanha) or die(mysql_error());
$qr = mysql_query($sql) or die(mysql_error());
$ln1 = mysql_fetch_assoc($qr1);
$ln2 = mysql_fetch_assoc($qr2);
$ln3 = mysql_fetch_assoc($qr3);
$horaatual = date('H:00');
$horas_hidden = array();
while ($ln = mysql_fetch_assoc($qr)) {
$horas_hidden[] = $ln['Hora'];
}
echo montarOptions($horas_hidden, 23);
function montarOptions($horas_hidden, $total_horas)
{
$html='<option value="">Selecione..</option>';
for ($i=0; $i <= $total_horas; $i++) {
$hora = ($i < 10) ? '0'.$i : $i;
$hora .=':00';
if (in_array($hora, $horas_hidden)) {
$html.= "<option hidden value=\"{$hora}\">{$hora}</option>";
} else {
$html.= "<option value=\"{$hora}\">{$hora}</option>";
}
}
return $html;
}
?>