...

View Full Version : Limit MYSQL query to not show duplicates



Crowds
01-24-2007, 01:56 AM
I am building a form that will include several options via a selection field.
My MySQL is structured as follows.


CREATE TABLE TUKO_support ( id INT(11) NOT NULL auto_increment, manuf varchar (100) NOT NULL default '', url VARCHAR(100) NOT NULL default '', name VARCHAR(100) NOT NULL default '', PRIMARY KEY (id))

I am using the following to fetch the data.


<?php

$query_supp = "SELECT manuf FROM TUKO_support ORDER BY manuf DESC" or die(mysql_error());
$list = mysql_query($query_supp) or die(mysql_error());
$row_m = mysql_fetch_assoc($list);

?>
<form action="" method="get">
<select name="manuf">
<?php do { ?>
<option><?php echo $row_m['manuf']; ?></option>
<?php } while ($row_m = mysql_fetch_assoc($list)); ?>
</select>

</form>

My problem is it is very likely that the 'manuf' field will contain the same entry more than once. I do not need this to happen as my next query will use the selected 'manuf' var to fetch all the data from the 'url and 'name' fields from every row that has the same 'manuf' entry.

How can I alter my query to limit this and stop the selection box from displaying the same data more than once ?

Crowds

koyama
01-24-2007, 02:01 AM
How about this?


"SELECT DISTINCT manuf FROM TUKO_support ORDER BY manuf DESC"

Crowds
01-24-2007, 02:10 AM
Thanks koyama !
Quick reply, and it was exactly what I needed :)
I should probably read the MySQL manual a bit more.

Rep added for your speedy reply.

Thanks again

Crowds



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum