0
Can someone tell me what’s going on in this code? The first querie works but it does not enter the condition within the for. The Second works and behaves normally, no problem with that. The case is that I’ve never seen it before my comparison inside the for it never gets true even though they both have the same length and being the same type.
follows the code:
public function getDias($dia){
$sql=$this->conn->query("SELECT * FROM agendamento WHERE dia = '$dia'");
// $sql=$this->conn->query("SELECT * FROM agendamento");
$horaBD = array(8=>"1");
$responseArr = [];
while($row = $sql->fetch_assoc()){
array_push($horaBD,date("H:i",strtotime($row['horario'])));
}
for ($i=9; $i <= 18; $i++) {
$horaFor = ($i<10) ? "0".$i.":00" : $i.":00";
if ($horaFor == @$horaBD[$i]) continue;//aqui eu substitui por and para funcionar do jeito esperado
else array_push($responseArr,$horaFor);
}
echo "<br>". json_encode($responseArr);
}
as recorded by Lipespry:
horaFor : 09:00 horaDB: 10:00
horaFor : 10:00 horaDB: 11:00
horaFor : 11:00 horaDB: 15:00
horaFor : 12:00 horaDB: 11:00
horaFor : 13:00 horaDB: 15:00
Try to rotate a
var_dump()
the two variables and visually compare the variables...– LipESprY
Thanks could see what I was doing wrong now I’m thinking of a solution. I will update the post to be more visible.
– Rodrigo Gabriel
@Lipespry I managed to make the comparison found out what was Thanks by the tip of var_dump().
– Rodrigo Gabriel
Fmz, Bro! Now answer your question and accept as solution.
– LipESprY
@Lipespry Do I even answer my question? can it Arnaldo? kkkk
– Rodrigo Gabriel
That’s right. Community recommendations. Keep your question from wandering around with no solution...
– LipESprY
Boy. It would not be simpler to select the times between 9 and 18 hours straight in the query. Its a mess your code. SELECT * FROM scheduling WHERE dia = '$dia' AND TIME(time) BETWEEN '12:00:00' AND '18:00:00'
– Marcos Xavier
@Marcosxavier I don’t think it would work because I need the times that are already scheduled between 12:00 and 18:00 to be subtracted from the final array showing only the available times, thanks for the tip. recognize that my code is messy, :) but I’m trying to improve, before nor did the object-oriented code kkkk,
– Rodrigo Gabriel