Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to store multiple values of a single field in a mysql db

Posted on 2006-06-25
3
Medium Priority
?
176 Views
Last Modified: 2010-04-07
I am using php/mysql.

I am trying to figure out what is the proper way organize multiple values for one field. On my website people play mixes and can choose any mix as one of there favorites.

I can store and view one favorite without issue but I dont know how to deal with multiple "favorites".

Should there be just one field called favorites which has multiple records in it? If this is the case how do I seperate the different "favorites" from one another.

Or should I have several fields such as favorite1,favorite2,favorite3 and have the dynamic table just pull these records.

Or am I completely off base and looking at it in the wrong way? I also have to do  this with the friends that users choose. Im really lost on how to set this up. Im pretty good with basic mysql/php but I have never had to store multiple values in this manner before.

Thank you in advance for any help, I really appreciate this site alot!

M




0
Comment
Question by:hep516
  • 2
3 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 2000 total points
ID: 16980727
Hi hep516,

Your first two options are not good.  Even if you wanted to store multiple values in one column on one row, it's just not good design.

Similarly, you do not want to store fav1, fav2, fav3, etc on the same row of the table because you then have to write code that handles a guy who only has one favorite versus a guy that has X favorites.  Again, not good design.

The best way to do is to allow users to enter their favorites as new rows in the table.  So you will have more than one table in the overall design...you will have at least two: users and favorites.  In all probability, you will have a third table that holds the different mixes, unless I misunderstand your design.  In users, there needs to be a unique primary key that identifies the user.  In mixes, you need a unique key that identifies the mix and a fields that holds the userID from users.  In favorites, you need a unique key for that, plus fields for userID and mixID.

Now, when a user selects a mix as a favorite, your site Inserts that into the favorites table.  To pull out a list of favorites per user, all you need to do write a select query that limits the favorites table by the current userID and returns the results in a repeat region.  So now your users can have unlmited favorites.
0
 

Author Comment

by:hep516
ID: 16980891
Thank you very much for your help.


0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 16980910
No problem.  This is all easily accomplished with the built-in behaviors, so if you get stuck, post back and I'll give you some more pointers.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I still run into .cgi files every now and then. In some instances, I actually prefer the simplicity of a .cgi script to other options. Since I use DreamWeaver extensively, what I needed was a way to open .cgi scripts in Dreamweaver. And I wanted to …
This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question