showing only unique entries in AutoSuggest
Posted: Wed Aug 27, 2008 3:59 am
Hi,
I am using an AutoSuggest box that runs from a MySQL database. However, I have one problem which is that my database has multiple entries of certain words so for example, if someone typed in 'd' they would get a list of the word 'doctors' ten times. How can I amend my code so that it only lists unique entries? Below is the code for the backend:
Thanks
Russ
I am using an AutoSuggest box that runs from a MySQL database. However, I have one problem which is that my database has multiple entries of certain words so for example, if someone typed in 'd' they would get a list of the word 'doctors' ten times. How can I amend my code so that it only lists unique entries? Below is the code for the backend:
Code: Select all
<?php
$db = new mysqli('129.0.0.1', 'asad' ,'asad', 'asad');
if(!$db) {
echo 'ERROR: 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 OrgType FROM Contacts WHERE OrgType LIKE '$queryString%' LIMIT 10");
if($query) {
while ($result = $query ->fetch_object()) {
echo '<li onClick="fill(\''.$result->OrgType.'\');">'.$result->OrgType.'</li>';
}
} else {
echo 'ERROR: There was a problem with the query.';
}
} else {
}
} else {
echo 'There should be no direct access to this script!';
}
}
?>Russ