www.webdeveloper.com
Results 1 to 4 of 4

Thread: Many fields in a Table Problem?

  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Many fields in a Table Problem?

    Hello,
    I am trying to create a table which stores what a person likes. For example:
    - Sports
    - Arts
    - Gadgets
    - Indoor Stuff
    - Outdoor Stuff
    - etc (the list goes on)

    What would be the best way for a database to store such information? I was thinking about having each category a individual field, and the value stored a Boolean (1=likes 0=dislikes...but this isn't very efficient).

    Any Suggestions?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,924
    I'd probably do it with 3 tables (including the users table)

    users
    ========
    id (int, primary key, auto-increment)
    <other user data...>

    likes
    ===========
    id (int, primary key, auto-increment)
    name
    <anything else you want to describe a "likes" thing...>

    users_likes
    ==========
    user_id (id from users table)
    likes_id (id from likes table)
    primary key(user_id, likes_id)

    Then each thing a user likes would be a separate row in the users_likes table
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2009
    Posts
    2
    Thanks for that. The solutions seems rather simply now.

    So as the user goes through the list of 'likes' (by clicking check boxes), when they click submit, then the database will create new entries in the 'likes' table which corresponds to the user table. Makes sense.

    Thanks again.

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    18,924
    No problem. Let us know how it works out.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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
  •  
HTML5 Development Center



Recent Articles