我创建了这个查询来使用 jQuery 显示我的自动完成框。它运行良好。
<?php
require_once('database.php');
if(isset($_POST['queryString'])) {
$queryString = $dbc->real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$q = "SELECT keyword
FROM (
SELECT tname AS keyword FROM t
UNION
SELECT sname AS keyword FROM sub
UNION
SELECT cname AS keyword FROM c
UNION
SELECT iname AS keyword FROM i
) s
WHERE keyword LIKE '%$queryString%'
LIMIT 10";
$r = mysqli_query ( $dbc, $q);
if($q) {
while ($row = mysqli_fetch_array($r, MYSQL_ASSOC)) {
echo '<li onClick="fill(\''.$row['keyword'].'\');">'.$row['keyword'].'</li>';
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
}
} else {
echo 'There should be no direct access to this script!';
}
?>
使用此查询根据关键字显示带有主题、导师姓名、城市的自动完整列表。现在我需要用更多值修改自动完成列表。例如,列表中有一个导师姓名,我想显示他/她的当前城市、他/她的个人资料图片等。这类似于 Facebook 搜索。
这是我的城市和地址表
# --------------
# Address Table
# --------------
CREATE TABLE address (
address_id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
address_one VARCHAR(40) NOT NULL,
address_two VARCHAR(40) DEFAULT NULL,
city_id INT(4) UNSIGNED NOT NULL,
PRIMARY KEY (address_id),
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
# --------------
# City Table
# --------------
CREATE TABLE city(
city_id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT,
city_name VARCHAR(30) NOT NULL,
district_id INT(2) UNSIGNED NOT NULL,
PRIMARY KEY (city_id),
UNIQUE (city_name)
) ENGINE=MyISAM;
我怎样才能做到这一点?