gpt4 book ai didi

php - 自动完成功能未按预期工作

转载 作者:行者123 更新时间:2023-12-01 04:14:44 25 4
gpt4 key购买 nike

我正在尝试创建自动完成功能,但当我在文本字段中输入姓氏时,它不显示全名。

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();

最佳答案

我认为您的 LIKE 参数中的 ? 参数没有被填充,因为它位于字符串中。如果您使用 MySQL,请尝试如下操作:

$cSQL="SELECT NOMBRE, APELLIDOS FROM personas WHERE APELLIDOS LIKE CONCAT('%', ?, '%') ORDER BY APELLIDOS";

对于 Oracle,请使用如下内容:

$cSQL="SELECT NOMBRE, APELLIDOS FROM personas WHERE APELLIDOS LIKE '%' || ? || '%' ORDER BY APELLIDOS";

关于php - 自动完成功能未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15854914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com