Results 1 to 2 of 2

Thread: Select ONE field from ALL records

  1. #1
    Join Date
    Jun 2013

    Select ONE field from ALL records

    Hey there,

    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?

    Please help!

  2. #2
    Join Date
    Aug 2004
    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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center