I want to be able to generate a drop down list from items entered into a row in a table in SQL. the row is called ‘locations’. so lets say, i have the following records:
- NAME | LOCATION
- img_01 | sydney
- img_02 | perth
- img_03 | perth
- img_04 | perth
- img_05 | melbourne
- img_06 | melbourne
What would be the best way to query the database to list the different locations in the db (only once for each location).
ie, would return
sydney, perth, melbourne.
Thanks.
To just get a list of locations use
You could then build your select by looping through those results.
Or you could alternatively do something like:
which would remove the need for you to loop through the results to build the options in html, you could just take that result and drop it between your select tags.