Check open and closed queries to include event in the calendar

Asked

Viewed 18 times

1

I am developing an online calendar and need to check when it includes an event if there is a date and time in scheduled and open consultations.

Queries marked in the database are "no".

Open queries in the database are "yes".

I made these selects in the database to do these checks above, but I did not have the expected result. It even marks the queries that are already on the register, but also includes in the database the same time (when it should not).

How can I fix this?

//$data_atual= date("d/m/Y");
$data_atual= $_POST['data'];

//echo $_POST['repita']."<br>";



$data = DateTime::createFromFormat('d/m/Y', $data_atual); // Define a data inicial
$fim = DateTime::createFromFormat('d/m/Y', $_POST['data_termino']); // Define a data final
$intervaloDias = $_POST['repita']; // Define o intervalo de dias

while ($data->format('Y-m-d') <= $fim->format('Y-m-d')) { // Verifica se a data é menor que a data final

$valor_start=$data->format('Y-m-d '.trim($_POST['hora_inicio']).":00".'');
$valor_end=$data->format('Y-m-d '.trim($_POST['hora_final']).":00".'');




$sql89 = "SELECT * FROM events WHERE start <='".$valor_start."' and end >='".$valor_end."' and ativo='sim'  and atendente='2'";

$result89 = $conn->query($sql89);

if ($result89->num_rows > 0) {
    // output data of each row
    while($row89 = $result89->fetch_assoc()) {

                      ?>

<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 ?></b></p>
<p><i class="m-r-10 mdi mdi-calendar-remove"></i> Final: <b><? echo $valor_end ?></b></p>
</div>      
</div>

<?
    }}
$sql98 = "SELECT * FROM events WHERE start <='".$valor_start."' and end >='".$valor_end."' and ativo='nao'  and atendente='2'";

$result98 = $conn->query($sql98);

if ($result98->num_rows > 0) {
    // output data of each row
    while($row98 = $result98->fetch_assoc()) {

                      ?>

<div class="col-md-6 ">
<div class="borda_data_erro">
<p><b><strong>Esse dia e horário já existe em Consultas marcadas</strong> </b></p>
<p><i class="m-r-10 mdi mdi-calendar-remove"></i> Início: <b><? echo $valor_start ?></b></p>
<p><i class="m-r-10 mdi mdi-calendar-remove"></i> Final: <b><? echo $valor_end ?></b></p>
</div>      
</div>

<?
    }}






else{
    mysqli_query($connection,"INSERT INTO `events` (
                                            `title` ,
                                            `atendente` ,
                                            `titulo_consulta` ,
                                            `start` ,
                                            `end` ,
                                            `uid` 
                                            )
                                            VALUES (
                                            '".$_POST["title"]." - ".$nomeUsuario."',
                                            '".mysqli_real_escape_string($connection,"$idusuario")."',
                                            '".mysqli_real_escape_string($connection,$_POST["title"])."',
                                            '$valor_start',
                                            '$valor_end',
                                            '".mysqli_real_escape_string($connection,$uid)."'
                                            )");
                                            $sql = "SELECT * FROM events order by id DESC LIMIT 0,1";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        //echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>";

        $id_evento= $row["id"];
    }
} else {
    echo "0 results";
}


mysqli_query($connection,"INSERT INTO `valor_consulta` (`id_evento` , `valor`)
                       VALUES (
                       '".mysqli_real_escape_string($connection,$id_evento)."',
                       '".mysqli_real_escape_string($connection,$_POST["valor_cosulta"])."'
                       )");



                                ?>
                      <div class="col-md-6">
<div class="borda_data">
<p><b>Consulta em aberto cadastrada2</b></p>
<p><i class="m-r-10 mdi mdi-calendar-check"></i> Início: <b><? echo $valor_start ?></b></p>
<p><i class="m-r-10 mdi mdi-calendar-check"></i> Final: <b><? echo $valor_end ?></b></p>
</div>
</div>

                      <?
}                         
                        $data = $data->add(new DateInterval('P'.$intervaloDias.'D')); // Incrementa a data

                                //echo $data->format('Y-m-d ') . "\n"; // Escreve a data na tela





                            }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.