Hi, I have a dropdown box extracted from MySQL database and I have two records for a product as it was produced in different years. i.e. model number 75 repeated, I am trying to extract only one of them in the dropdown box and have used select distinct but it still extracts the both duplicate number. If possible can someone explain what I am doing wrong?

Here is the SQL code that I am using:

$query="SELECT DISTINCT vehicles.vehicles_model, manufacturer.manufacturer_name, vehicles.vehicles_year
FROM category as category
JOIN vehicles as vehicles on category.category_ID = vehicles.FK_category_ID
JOIN products as products on products.products_id = vehicles.FK_products_ID
JOIN manufacturer as manufacturer on manufacturer.manufacturer_ID = vehicles.FK_manufacturer_ID 
WHERE vehicles.FK_category_ID = '$category_id' and manufacturer_name='$make'";

//Start of form
echo "<form action=\"cat.php\" method=\"post\">\n";

// read database values
$result = mysql_query ($query);
echo "<select name=vehicles_model value=''><option>Select your vehicle</option>";
// printing the list box select command

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt

echo "<option value=$nt[vehicles_id]>Model: $nt[vehicles_model] Year: $nt[vehicles_year]</option>";
/* Option values are added by looping through the array */
		
}

echo "</select>";// Closing of list box

Recommended Answers

All 2 Replies

remove
, vehicles.vehicles_year
from your query.

Thanks sorted

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.