Reputation: 533
I'm trying to create a autocomplete but when I'm typing a surname in the textfield, it doesn't show the full name.
JavaScript:
$(document).ready(function(){
$("#txtBuscar").autocomplete("autocomplete.php", {
selectFirst: true
});
});
PHP:
require('conecta.php');
ini_set('display_errors',1); error_reporting(E_ALL);
$cSQL="SELECT NOMBRE, APELLIDOS FROM personas WHERE APELLIDOS LIKE '%?%' ORDER BY APELLIDOS";
$stmt=$oConni->prepare($cSQL) or die($oConni->error);
$stmt->bind_param('s',$_GET['q']);
$stmt->execute();
$stmt->bind_result($nombre,$apellidos);
while ($stmt->fetch()) {
echo $apellidos.', '.$nombre."\n";
}
$stmt->close();
Upvotes: 2
Views: 70
Reputation: 1287
I think the ?
parameter in your LIKE
argument doesn't get filled in since it is in a string. If you're using MySQL, try something like this:
$cSQL="SELECT NOMBRE, APELLIDOS FROM personas WHERE APELLIDOS LIKE CONCAT('%', ?, '%') ORDER BY APELLIDOS";
For Oracle, use something like this:
$cSQL="SELECT NOMBRE, APELLIDOS FROM personas WHERE APELLIDOS LIKE '%' || ? || '%' ORDER BY APELLIDOS";
Upvotes: 2