検索を可能にするこの単純なフォームがあり、結果をDIVに表示したいので、ajaxを使用しています。
<script type="text/javascript">
$(document).ready(function(){
$('#boton_cargar').click(function() {
var nombre = $("#nombre").val();
$.ajax({
type: "GET",
url: 'resultados.php?nombre='+nombre,
success: function(data) {
$('#resultados').html(data);
$('#resultados div').slideDown(1000);
}
});
});
});
</script>
<form>
<input id="nombre" name="nombre" type="text" />
<input name="boton_cargar" id="boton_cargar" type="button" value="buscar" />
</form>
<div id="resultados">
// I want to show results here
</div>
これはresultados.phpです
<?php
include('loader.php'); //call db
$conn = new conection();
$rs = new RecordSet($conn);
if(isset($_GET['nombre']))
$sql="SELECT * FROM clientes INNER JOIN alquiler ON clientes.id_cliente = alquiler.id_cliente INNER JOIN insumos ON insumos.id_insumo = alquiler.id_insumo WHERE `clientes`.`nombre` = {$_GET['nombre']}";
else
die('error');
unset($rs);
unset($conn);
?>
<?php foreach($resultados as $res){ ?>
<?php echo $res->nombre ?>
<?php }?>
たとえば、「jhon」を {$_GET['nombre']} に置き換えると、結果を取得できます。
よろしくお願いします。