我已经使用数据库中的数据实现了jquery ui自动完成功能。现在我所做的只是显示一个字段。比方说,我有一个数据库:
| id | suburb | code
0 DAR 10
1 ASD 20
2 DEF 30
and so on....
我的HTML代码:
<form id="auto_test">
<label for="tags">Tags: </label>
<input id="tags" type="text" name="tags" />
<input type="button" id="auto_test_btn" value="save" />
jquery的:
jQuery("#tags").autocomplete({
source: "<?php echo WP_PLUGIN_URL.'/plugin_name/php_file.php'?>"
});
php:
$t = $_GET['term'];
$code = $wpdb->get_results(
"SELECT suburb as label, suburb as value
FROM Sheet1
WHERE suburb like '%$t%'
LIMIT 25
",ARRAY_A
);
echo(json_encode($code));
自动完成功能仅显示“郊区”,因为它被定义为标签。我想要做的是显示郊区和代码。
做什么好事?
答案 0 :(得分:2)
您可以在SQL select语句中连接列(使用适当的分隔符),可能是这样的:
"SELECT Concat(suburb, ' ', code) as label, suburb as value
答案 1 :(得分:2)
"SELECT concat(suburb, ' ', code) as label, suburb as value
答案 2 :(得分:0)
试试这个你的SQL查询..
SELECT suburb as label, code as value
FROM Sheet1
WHERE suburb like '%$t%'
LIMIT 25