a screen that allows searches of vehicle availability, where the customer can choose the car, and tell the date and time of collection and delivery. The search result must be updated by Ajax, as soon as conditions change.
index.php
$obj = new Arriendo_autos();
print "<h1>Arriendo de autos</h1>";
print "<form action='#' method='post'>";
print "Fecha de arriendo";
print "<input type='text' id='fechaa' name='fechaa'>";
print "Fecha de devolución";
print "<input type='text' id='fechad' name='fechad'>";
print "<br>";
print "<input type='submit' id='btn' value='Buscar'>";
print "</from>";
print "<div id='responsecontainer' align='center'>";
<script type="text/javascript">
$(document).ready(function(){
function mostrarBD() {
$.ajax({
url: 'buscador.php',
type: 'get',
datatype: 'html',
data: {search: $('#btn').val()},
success: function(response) {
$("#responsecontainer").html(response);
},
error : function() {
alert("Error!");
}
});
}
$('#btn').click(function(){
mostrarBD();
});
$('form').submit(function(e){
e.preventDefault();
mostrarBD();
});
});
</script>
searcher.php
$obj = new Arriendo_autos();
$arriendos = $obj->getBuscar();
print "<table>";
if (is_array($arriendos) || is_object($arriendos))
{
foreach ($arriendos as $arriendo)
{
print "<tr>";
print "<td>".$arriendo["titulo"]." <a href='#'>Reservar</a></td>";
print "</tr>";
}
}
print "</table>";
function.php
function getBuscar()
{
$fechaa = (isset($_GET['fechaa']) ? $_GET['fechaa'] : null);
$fechad = (isset($_GET['fechad']) ? $_GET['fechad'] : null);
echo $sql = "SELECT * FROM arriendos AS a INNER JOIN incidentes AS i ON a.idarriendo = i.idarriendos WHERE a.fecha_arriendo >= '".$fechaa."' AND a.fecha_devolucion <= '".$fechad."'";
$res = $this->mysqli->query($sql);
while($row = $res->fetch_assoc())
{
$data[] = $row;
}
if(isset($data))
{
return $data;
}
}