使用PHP使用MySQL表中的值填充搜索输入框 [英] Populating a search input box using PHP with values from a MySQL table
问题描述
我目前正在使用此JQuery 作为我网站上的搜索框. Javascript当前从.txt文件中调用值以获取自动完成结果.但是,由于我希望站点最终可以让用户选择添加这些值,所以我希望它从数据库表中调用值.
Im currently using This JQuery as a search box on my website. The Javascript currently calls in values from a .txt file for the autocomplete results. However as I want my site to eventually have the option of the user adding these values, I'd like It to call in values from my database table instead.
索引页上的jQuery调用.txt文件:
JQuery on index page that calls the .txt file:
$(document).ready(function(){
$("#select3").fcbkcomplete({
json_url: "data.txt",
addontab: true,
maxitems: 10,
input_min_size: 0,
height: 10,
cache: true,
newel: true,
select_all_text: "select",
});
});
.txt文件的格式:
Formatting of the .txt file:
[{"key": "hello world", "value": "hello world"}, {"key": "movies", "value": "movies"},
我认为解决方案将不是调用data.txt,而是调用data.php并让此代码提取值:
I thought the solution would be instead of calling data.txt, to call data.php and have this code pull in values:
$getData = mysql_query("SELECT Name FROM tblCocktails");
while($info = mysql_fetch_array($getData))
{
echo "key: value:".$item['Name']"key: value:".$item['Name']';
}
但是,这似乎不起作用,我在Dreamweaver上进行的调试已决定不起作用.任何帮助将不胜感激.
however this doesn't seem to work and my debugging on dreamweaver has decided to not work. Any help would be appreciated.
推荐答案
在while循环中,查看echo
行.您应该将项目替换为信息.
In while loop look at the echo
line. You should replace item with info.
喜欢这个.
$getData = mysql_query("SELECT Name FROM tblCocktails");
while($info = mysql_fetch_array($getData))
{
echo "key: value:".$info['Name']."key: value:".$info['Name'];
}
这篇关于使用PHP使用MySQL表中的值填充搜索输入框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!