Solved

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

Posted on 2006-06-25
3
149 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 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now