Query in two tables simultaneously with two different parameters [closed]

-6

Hello, good evening!

I'm creating a schedule of events by time, in different places. So I need you to show the locations before the event is scheduled, after the places available, I need to display the available times.

I have tried to search here and in several other places, but I have not found a solution that suits.

I have 5 tables with 28 identical times, but with different locations.

Basically, using Ajax, I can find the location and times available, but how can I find it for different days?

Date Declaration
The returnSalas (); only returns which rooms have been registered in the DB

<div class="form-group col-md-6">
   <label for="data">Data:</label>
   <input type="date" name="data" id="data" onchange="returnSalas();" placeholder="Data" class="form-control">
</div>

Return of the rooms in the DB

<div class="form-group col-md-6">
    <label for="sala_de_aula">Sala:</label>
    <select name ="sala_de_aula" id="sala_de_aula" class="form-control" onchange="returnHorariosDisp();">
        <?php
           if (!isset($_GET['DataSelecionada'])) {
        ?>
             <option disabled selected>Informe a data Primeiro</option>
        <?php
              }
        ?>
     </select>
</div>

The role of Ajax is to return the rooms in the above section
returnHarariosDisp (); = Search the available times of this room and return in the next section: p>

<div class="form-group col-md-6">
   <label for="horario_entrada">Horário de Entrada</label>
   <select name="horario_entrada" id="horario_entrada" class="form-control">
      <?php
         if (!isset($_GET['SalaSelecionada'])) {
      ?>
          <option disabled selected>Selecione a sala de aula</option>
      <?php
            }
      ?>
    </select>
</div>

The database has the following tables:

  • Room1
  • Room2
  • Room3
  • Room4
  • Room5

Each of the tables have the columns:

  • id (int / a_i)
  • input (float) 8 through 21.5
  • output (float) 8.5 to 22
  • status (int) 0 = free | 1 = busy
  • view_input (varchar) 08:00 to 21:30
  • display_out (varchar) 08:30 to 22:00

All is well, the records are written to another table named _agenda_aulas_, the table's composition looks like this:

  • id (int / a_i)
  • matricula_aluno (int null)
  • child_name (varchar)
  • data (varchar)
  • prof (varchar)
  • input (varchar)
  • output (varchar)
  • matter (varchar)
  • qtd_hours (float)
  • value (float)
  • payment (varchar)

Programming is working, either to store the values in the table addressbook , or to update the table according to the selected room.

Excerpt that does the programming:     

    //Pré Cadastro do aluno
    $QueryConsultarAlunos = "SELECT * FROM alunos WHERE matricula_aluno = '$matricula'";
    $ExeQrConsultarAlunos = mysql_query($QueryConsultarAlunos);
    if (!$ExeQrConsultarAlunos) {
        echo $QrPreCadastrarAluno = "INSERT INTO alunos (matricula_aluno,nome_aluno) VALUES ('$matricula','$nomeAluno')";
        $cadastrarAluno = mysql_query($QrPreCadastrarAluno, $db);
        echo '<br>';
    }

    echo $QrUpdateHorarioSalas = "UPDATE $salaDeAula SET status = 1 WHERE entrada = $horarioEntrada";
    mysql_query($QrUpdateHorarioSalas);
    echo "<br>";

    echo $QrCadastrar = "INSERT INTO agenda_aulas (matricula_aluno,nome_aluno,data,sala,prof,entrada,saida,materia,qtd_hora,valor,pagamento) VALUES ('$matricula','$nomeAluno','$dataAula', '$salaDeAula', '$professor', '$horarioEntrada', '$horarioSaida','$materiaAula','$tempoDeAula','$valorDaAula','$pagamentoAula')";
    $cadastrar = mysql_query($QrCadastrar, $db);
?>


But as I said at the beginning, I need this same information from each room, but with the filter per day.

I thought about creating new tables declaring the date as the name:

<?php
$tabelaDataAgendamento = 'ag_' . date('d_m_Y', strtotime($dataAula));
$resultAgData = mysql_query("SHOW TABLES LIKE '$tabelaDataAgendamento'");
$tabelaExists = mysql_num_rows($resultAgData) > 0;

if ($tabelaExists) {
    echo $QueryInserirTabelaData = "INSERT INTO '$tabelaDataAgendamento'(matricula_aluno,nome_aluno,sala,prof,entrada,saida,materia,qtd_hora,valor) VALUES('$matricula','$nomeAluno','$salaDeAula','$professor','$horarioEntrada','$horarioSaida','$materiaAula','$tempoDeAula','$valorDaAula')";
    $inserirTabelaData = mysql_query($QueryInserirTabelaData);
    echo "<br>";
    if ($inserirTabelaData):echo "Inserido!";
    else: echo "Não Inserido! Erro: " . mysql_error();
    endif;
    echo "<br>";
} else {
    echo $QueryCriarTabelaData = "CREATE TABLE '$tabelaDataAgendamento'(id int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, matricula_aluno int, nome_aluno varchar(255),sala varchar(255),prof varchar(255),entrada float,saida float,materia varchar(255),qtd_hora float, valor float)ENGINE=INNODB;";
    mysql_query($QueryCriarTabelaData);
    echo "<br>";
}

But the problem is when I check the records before inserting a new record, I do not know how to perform the filter.

I'm breaking my head to fix this for almost a week, can anyone help me to solve this problem?

Thanks in advance for the help!

    
asked by anonymous 29.12.2016 / 00:13

1 answer

0

Hello let me see if I understood, do you need to filter the 5 rooms to have the same information with different parameters in the room search?

Well, if that's what I believe, a union of all the rooms would solve Ex: select id, data from tab1 where id = 1 union select id, data from tab2 where data < > 0;

    
03.01.2017 / 16:00