我正在编写一个网站以了解更多关于PHP的信息,并正在制作JQuery Autosuggest。这里的脚本。
这是我的autosuggest.php代码:
<?php
$db = new mysqli('localhost', 'root' ,'***********', '**********');
if(!$db) {
echo 'Could not connect to the database.';
} else {
if(isset($_POST['queryString'])) {
$queryString = $db->real_escape_string($_POST['queryString']);
if(strlen($queryString) >0) {
$query = $db->query("SELECT * FROM company WHERE name LIKE '$queryString%' LIMIT 10");
if($query) {
echo '<ul>';
while ($result = $query ->fetch_object()) {
echo '<li onClick="fill('''.addslashes($result->name).''');">'.$result->name.'</li>';
}
echo '</ul>';
} else {
echo 'OOPS we had a problem :(';
}
} else {
// do nothing
}
} else {
echo 'There should be no direct access to this script!';
}
}
?>
现在,我不想只在公司表中搜索名称,而是想在另一个表(称为cat)中搜索cat字段,并在不同的表中搜索subcat 我的表格结构: 这里(我还不能发布图片) 所以我想从三张表中搜索。这可能吗?我如何用我的代码做到这一点? 谢谢你的帮助!
您应该在3个表中的每一个表之间执行UNION
,并将数据规范化为Name
、ID
和Type
列。