I have a table with entries such as:
123 (DVD)
123 [DVD] [2007]
125 [2009]
189 (CD)
when I present these to the user in an autocomplete field I do away with anything between either () or [] as these are not relevant, but, as you can see from the list above, that leaves me with two entries for 123 which appear in the dropdown... is there anyway to further suppress duplicates? Sometimes there can be as many as 5 or 6 which looks wrong to say the least! Code below:
// db select
$query = "SELECT $title FROM PRprodINFO2 WHERE ((prodcatID = '$cat_id') AND ($title LIKE \"%" . $_GET["q"] . "%\")) group by $title LIMIT 8";
$result = mysql_query($query);
$output_items = array();
// while loop to print results
while($row = mysql_fetch_array($result)) { $output_items[] = $row[$title]; }
$output_items = preg_replace('/\[.*?\]|\s*/', '', $output_items); // remove [blah]
$output_items = preg_replace('/\(.*?\)|\s*/', '', $output_items); // remove (blah)
print(implode("\n", $output_items));
Many thanks