Return unique results from exploded array (NEED HELP FAST PLEASE)



Ok, I have returned a field from my database named “description” and have done so using DISTINCT as to only get unique values.

This outputs something like “Vauxhall Corsa 1.2 SXI” and if there were 2 like that it would only get one which is what I wanted, however I am now building search fields and need the “Make” field to only return the Make of each car, so “Vauxhall” and the problem being that even though these 2 are unique…

Vauxhall Corsa 1.2 SXI
Vauxhall Astra 1.4

I need to only return the make so “Vauxhall”.

I used an explode function to only return the first word “Vauxhall” and put this in a while loop as to return the make for each car. Problem is now that I have…


And I need to onlydisplay 1 instance of each word and “array_unique” doesn’t seem to be having any effect.

Here is the chunk of mentioned code…

$sql = “SELECT DISTINCT * FROM database”;
$query = mysql_query($sql);
while ($search = mysql_fetch_array($query))
$explode = explode(" ", trim($search[‘description’]));
echo “<option class = “make”>”;
echo $explode[0];
echo “”;

PLEASE help urgently!

Thank you.


Just like SQL, you can use UNIQUE in PHP. Here is the link that explains it. Look at the samples down the page a little… Hope that helps…