Select ONE field from ALL records
I am trying to build a "search dropdown" feature.
basically what I am trying to do is go through my database collecting the 'type' field from all records, then putting each type in a dropdown menu.
Also, there are obviously more than one instance where the type is the same as another (ie: a place is a bar, so is another place) how can I get this to only put one "bar" in the dropdown?
You can use the "DISTINCT" modifier in your query so that you eliminate duplicates.
If feasible, a more robust solution would be a separate table that defines the possible values for these values, then in the table with the actual data you just reference the primary key of this new table (i.e. use a foreign key). This eliminates the worry that one record has a value of "Bar", another "a bar", and yet another has "pub". The downside is you need to keep this table updated with possible values. I suppose another possibility would be to make the field in the main table an ENUM type and not bother with the 2nd table, though that still requires the need to update the allowed ENUM types as your needs change.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread