Getting mysql data for a dropdown
Results 1 to 2 of 2

Thread: Getting mysql data for a dropdown

  1. #1
    Member
    Join Date
    Sep 2004
    Posts
    94

    Getting mysql data for a dropdown

    Hello, I am sure this will have been covered many times, I have searched quite a bit but I am not sure how to word what it is I am looking for, sorry!

    I have a database listing cats (Bill, Bob, Tabatha, etc).
    Each cat's could have multiple behaviour traits (Sleepy, Active, Inquisitive, etc).
    So as I don't want to have a behaviour column storing an array, I create another table with column names for each type of behaviour. Cat Bill gets a row in the new table with either 1 or 0 to identify whether he has each behaviour type.

    However, on my page I want to create a dropdown which will show all used behaviour types but I have no idea how to do this. So:

    Bill: Sleepy
    Bob: Sleepy, Inquisitive
    Tabitha: Inquisitive

    The drop down should show Sleepy and Inquisitive but not Active.
    Any help would be very much appreciated!
    Thank you

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,353
    Will the "behavior traits" ever change? For example, would you ever add, remove, or modify them? If so, I would suggest three tables: one for cats, one for behavior traits, and that relates the two. Each row in the "relation" table would consist of two elements - a candidate key from the cats table and one from the behavior table.

    Otherwise, you'll want to build an array of all possible traits in PHP, and then you'd loop through that array to output the ones that have the "1" value in the row retrieved from your current SQL schema.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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