gpt4 book ai didi

mysql - Javascript 自动完成列出 MySQL 结果

转载 作者:行者123 更新时间:2023-11-29 13:41:30 25 4
gpt4 key购买 nike

我有一个自动完成脚本来查找 Var 标签,我的问题是,如何使用 MySQL 的结果填充“avaiableTags”?

$SQL = "从用户中选择用户名";例如

(function($) {
$(document).ready(function(e) {
if($.fn.autocomplete) {
var availableTags = [
"User 1", //mysql result here
"User 2",
"ecc..."
];

最佳答案

//javascript
<script type="text/javascript">
$(function() {

//autocomplete
$(".auto").autocomplete({
source: "search.php",
minLength: 1
});

});
</script>

//search.php something like this

$stmt = $conn->prepare('SELECT country FROM countries WHERE country LIKE :term');
$stmt->execute(array('term' => '%'.$_GET['term'].'%'));

while($row = $stmt->fetch()) {
$return_arr[] = $row['country'];
}

有关完整示例,请查看此处 http://www.daveismyname.com/tutorials/php-tutorials/autocomplete-with-php-mysql-and-jquery-ui/

关于mysql - Javascript 自动完成列出 MySQL 结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18020535/

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