0
I’m making an online schedule and I need to check the schedules that are already scheduled so as not to conflict with the schedule to schedule.
I’m using PHP’s BETWEEN to compare times, but it’s not working.
Example
Time to be scheduled
inicio: 2019-03-11 09:30:00
Final: 2019-03-11 09:45:00
In the bank I have registered:
inicio: 2019-03-11 09:00:00
Final: 2019-03-11 10:00:00
I select the bank to be able to check the schedule to be scheduled:
$valor_start= $hoje->format('Y-m-d '.trim($_POST['hora_inicio']).":00".'') ;
$valor_end= $hoje->format('Y-m-d '.trim($_POST['hora_final']).":00".'');
$sql="SELECT * FROM `events` WHERE `start` BETWEEN '".implode('-', array_reverse(explode('/', substr($valor_start, 0, 10)))).substr($valor_start, 10)."' AND '".implode('-', array_reverse(explode('/', substr($valor_end, 0, 10)))).substr($valor_end, 10)."' and ativo='sim' and atendente='".$_POST['atendente']."'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
?>
<div class="col-md-6 ">
<div class="borda_data_erro">
<p><b><strong>Esse dia e horário já existe em Consultas abertas</strong> </b></p>
<p><i class="m-r-10 mdi mdi-calendar-remove"></i> Início: <b><? echo $valor_start ."-".$row['start']?></b></p>
<p><i class="m-r-10 mdi mdi-calendar-remove"></i> Final: <b><? echo $valor_end ."-".$row['end']?></b></p>
</div>
</div>
<?
$checar_horarios=$row['start'];
}}
Should return the error This day and time already exists in Open Consultations but it doesn’t happen, as it could solve?
What is the result of this
$result
wheel onevar_dump($result)
and tell me the result ?– Bulfaitelo
The date field is as varchar? pq this conversion in format?
– rray
why it comes from the form so 11/03/2019
– Wagner
@Bulfaitelo the var_dump($result) returns this Object(mysqli_result)#6 (5) { ["current_field"]=> int(0) ["field_count"]=> int(10) ["lengths"]=> NULL ["num_rows"]=> int(0) ["type"]=> int(0) }
– Wagner
Wheel one
var_dump($sql)
– Bulfaitelo
returns this string(124) "SELECT * FROM
events
WHEREstart
BETWEEN '2019-03-11 9:30:00' AND '2019-03-11 9:45:00' and active='yes' and attendant='2'"– Wagner
To enlighten you,
BETWEEN
is an SQL operator, not PHP.– bfavaretto