2
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 chosen date is today and now is 16:13, my input should display
17:00 - 18:00 - 19:00 - 20:00 - 21:00 - 22:00 - 23:00
Follows 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;
}
?>
Good morning, the code works but if the chosen date is tomorrow the field still performs the filter I tried to solve here with an if more could not
if($predata == $hoje) continue;
, i need the filter to occur only if the chosen date is equal to today.– Matheus Arruda
I changed the answer, just you capture the current date and on
if
comparing schedules, comparing the full date– Jeferson Assis
Good afternoon, I tried to do this way but it appears all available hours even if I select today’s date.
– Matheus Arruda
You are changing the variable date
$dataSelecionada
?– Jeferson Assis
Yes, I put
$dataSelecionada = $predata
– Matheus Arruda
The format of this
$predata
this inY-m-d
?– Jeferson Assis
No, but I made the change, my date format is d m Y, in your code I made the adaptation
strtotime(date('d\m\Y H:i')))
, I also did the test by placing the date selected manually and with its format and got the same problem.– Matheus Arruda
The
strtotime
only accepts date formats in English, you must leave as this in the code and change your date to the correct format– Jeferson Assis