Hey All,
This may seem like a confusing question, but hopefully I explain it well. First off that might help, this in relation to motorcycles, so that will help explain table names and such.
I want to create drop down menu's where people have the option of selecting possible choices, say "Yamaha" and (in later code) a script will search through the table and find all entries with Yamaha in them.
Now I have a table in MySQL with the following items:
year, make, model
Problem is that my table isn't complete yet, because I do not know all of the bikes yet. Now what I want is a dynamic drop down menu based on what is already in the tables. Meaning if I only have "Honda" and "Yamaha" in the tables, I only want the drop down menu to list those two makes (does that make sense?).
Now here is the initial code I have going (this is a snipet):
// Start 'make' drop down menu
$sql = "SELECT * FROM search WHERE (make != \"0\") ORDER BY make";
$result = mysql_query($sql);
print "<select name=\"make_dropdown\">";
print "<option value=\"Select_One\">Select One</option>";
while ($row = mysql_fetch_row($result) ) {
print "<option value=\"".$row[2]."\">".$row[2]."</option>";
}
print "</select>";
// End 'make' drop down menu
Now the problem as you can probably see is if I have 3 entries in the table with "Yamaha", those three entries are put into the drop down menu, meaning I have duplicates.
Now for my question 🙂 Is there any quick and easy code I can add to this, hopefully in the "SELECT..." query to only give me one of each, and discard duplicates?
Of course I can write an algorithm to get a list of the non-duplicates, then run a loop and put them into the drop down menu, but what I'm looking for is some quick, dirty solution 🙂
Any help?
Please let me know if you have any questions reguarding this.
Thanks