Select dependent with three levels

Asked

Viewed 356 times

2

I am setting up a simple system of booking vehicles for the company and I need to assemble a "triple" combo that will check the vehicle and the available schedules for it. I set up a double of the expected departure and arrival time, where the expected time is always higher than the one selected as output. Using these bases, any suggestions?

sql reserves.

--
-- Estrutura da tabela `reservas`
--

CREATE TABLE IF NOT EXISTS `reservas` (
  `cod` int(10) NOT NULL AUTO_INCREMENT,
  `cod_usuario` int(10) NOT NULL,
  `cod_veiculo` int(10) NOT NULL,
  `destino` varchar(100) NOT NULL,
  `data_saida` date NOT NULL,
  `hora_saida` varchar(6) NOT NULL,
  `cod_hora_saida` int(2) NOT NULL,
  `data_retorno_prev` date NOT NULL,
  `hora_retorno_prev` varchar(6) NOT NULL,
  `cod_hora_prevista` int(2) NOT NULL,
  `data_retorno_real` date NOT NULL,
  `hora_retorno_real` varchar(6) NOT NULL,
  `usuario` varchar(30) NOT NULL,
  `ultima_atualizacao` date NOT NULL,
  PRIMARY KEY (`cod`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

index php.

            <tr>
                 <td>Veiculo Desejado: </td>
                 <td><select id="CmbVeiculo">
                     <option  value="">Selecione...</option>
                      <?php
                       foreach($pdo->query('SELECT cod, modelo FROM veiculos order by cod') as $row){
                          echo '<option value="'.$row['cod'].'">'.$row['modelo'].'</option>';
                       }
                       ?>
                 </select></td>
             </tr>

             <tr>
                 <td>Hora Desejada: </td>
                 <td><select id="CmbHora">
                     <option  value="">Selecione...</option>
                      <?php
                       foreach($pdo->query('SELECT cod, horario FROM horarios order by cod') as $row){
                          echo '<option value="'.$row['cod'].'">'.$row['horario'].'</option>';
                       }
                       ?>
                 </select></td>
             </tr>

             <tr>
                 <td>Hora Prevista de Retorno: </td>
                 <td><select id="CmbHoraVolta">
                     </select>
                      <script type="text/javascript">
                            $(document).ready(function() {
                            $('#CmbHora').cascade({
                            source: "call_hora.php",
                            cascaded: "CmbHoraVolta",
                            extraParams: { cod: function(){ return $('#CmbHora').val();  } },
                            dependentLoadingLabel: "Carregando ...",
                            dependentNothingFoundLabel: "Não existe hora vaga",
                            dependentStartingLabel: "Selecione a saida",
                      });
                     });
                    </script>
                  </td>
              </tr>

call_hora.php

<?php
    if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && $_SERVER["HTTP_X_REQUESTED_WITH"] === "XMLHttpRequest"){
        include 'js/conn.php';
        $ufid = filter_input(INPUT_GET, 'cod', FILTER_SANITIZE_NUMBER_INT);
        if ($ufid){
            $query = $pdo->prepare('SELECT cod as value, horario as label FROM horarios where cod>? ORDER BY cod');
            $query->bindParam(1, $ufid, PDO::PARAM_INT);
            $query->execute();
            echo json_encode($query->fetchAll());
            return;
        }
    }
    echo NULL;
?>

  • 1

    http://answall.com/q/95247/3938

  • Solved your doubt?

  • Yes, with the marcusagm link

No answers

Browser other questions tagged

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