I am using Paper Mashups Autosuggest.
I just finished doing a mysql union to bring three tables into one so I could autosuggest names of companies, names of categories and names of subcategories. Unfortunately, while that worked, it added extra li’s ( I think that’s what they are, here’s the picture.)
How do I get rid of those extra li’s?
Here’s my code:
<?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 name FROM company WHERE name LIKE '$queryString%' UNION SELECT cat FROM cat WHERE cat LIKE '$queryString%' UNION SELECT subcat FROM subcat WHERE subcat LIKE '$queryString%' LIMIT 10");
if($query) {
echo '<ul>';
while ($result = $query ->fetch_object()) {
echo '<li onClick="fill(\''.addslashes($result->name).'\');">'.$result->name.'</li>';
echo '<li onClick="fill(\''.addslashes($result->cat).'\');">'.$result->cat.'</li>';
echo '<li onClick="fill(\''.addslashes($result->subcat).'\');">'.$result->cat.'</li>';
}
echo '</ul>';
} else {
echo 'OOPS we had a problem :(';
}
} else {
// do nothing
}
} else {
echo 'There should be no direct access to this script!';
}
}
?>
Thanks for all help!
Looks to me like it’s spitting out blanks. Try just using name first, then just cat, then just subcat to find the culprit. Also, your subcat in your three echoes is echoeing cat instead of subcat…
Should be: