I am putting together a simple vehicle reservation system for the company and need to set up a "triple" combo that verifies the vehicle and the times available for it. I made a double of the expected departure and arrival time, where the expected time is always greater than the one selected as departure. Using these bases, any suggestions?
reserves.sql
--
-- 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;
?>