1
I am trying to implement a block scheduling system where the user chooses the date and location of his preference. After that, he will choose the times according to availability and need to block schedules that are unavailable. I tried to search the database and create an array of all schedules that are possible to schedule to compare with the results obtained, but I believe that I am with some logic error, because the function mysqli_fetch_array does not return all values and starts a new search when it falls in the if() condition I put. Exemplifying:
Have been scheduled the times of 18h00, 19h00 and 20h00 for the day 28/05/2018 on the court whose id = 1.
With the code below, it returns me 3 entire columns with the arrays specified, and in the first column only the time of 18h00 appears unavailable, in the second column only 19h00 and in the third column only 20h00 as unavailable.
Any idea to adjust and bring me just a column with the three times unavailable? Thank you so much already
$consulta_sql= "SELECT hora_agendada FROM tabela_agendamentos WHERE data='$data_escolhida_pelo_usuario' AND id_quadra_escolhida_pelo_usuario='1'";
$query = mysqli_query($infos_conexao, $consulta_sql)
while ($dados_do_mysql = mysqli_fetch_array($query)){
foreach ( array("9:00","10:00","11:00","12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00","20:00","21:00","22:00","23:00") as $hora_array ) {
if($hora_array == $dados_do_mysql['hora']){
$hora_array ='Horário Indisponível';
}
echo $hora_array;
}
}
You’re a little confused, you can add an image of how the output is and how it should come out
– Costamilam
Image added with the output of 3 searches I commented. It should only appear one of them with registered times in the bank appearing as "Unavailable". I thank you already.
– thomasferreira
Now it became clearer, this occurs because of the two loops, one inside the other, use the function
in_array
as in the answer– Costamilam