Howto get multiple values from 1 row
Moderator: General Moderators
Howto get multiple values from 1 row
Ok, i have a database, and a user, the user can gt given awards, but how can i query the database to Get the actuall awards, each u ser can have more than 1 award. i just can't seem to think of a practical way to do it :/ any ideas?
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
No, they are stored in separate records. Using a single cell to store the data would result in a very finite number of awards someone could have. Using a linking table, that number is only limited by your operating system's storage limits.
This is called a many-to-many relationship between users and awards. In relational databases that requires a third table to cross link between any number of users and any number of awards.
This is called a many-to-many relationship between users and awards. In relational databases that requires a third table to cross link between any number of users and any number of awards.
-
Shendemiar
- Forum Contributor
- Posts: 404
- Joined: Thu Jan 08, 2004 8:28 am
No No! We do not support bad practices here at devnet! Why store an array in string format and do all that parsing???Shendemiar wrote:Use var_export to transform php-array to a string that is stored in databasedanharibo wrote:i think i understand, but can i store multiple Variables in 1 cell?
Do not listen to this fella. Listen to feyd. He was correct. Set up your user table:
user_id, name, other_user_info, etc.
Now set up your award table
award_id, awardname, etc.
Now set up a third table like this:
user_id, award_id
Code: Select all
Now see you can have records like this:
user_id award_id
1 12 User one has award #12
1 32 User one also has award #32
2 32 User two has award #32 also
2 16 User two also has award #16If you do not know how to select information given this schema, you need to research the term "sql joins"
Google is a good start... if you are working with mysql, then mysql's site is another excellent resource!
-
Shendemiar
- Forum Contributor
- Posts: 404
- Joined: Thu Jan 08, 2004 8:28 am