Advertisement

02.28.2008 at 07:15AM PST, ID: 23200512
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.8

Best Practice for storing multiple variable named records associated with a master record

Asked by unobserved in MySQL Server

Tags: , ,

I'm working on a fairly simple contact database system with the exception that on a per installation basis, the system needs to handle "extra fields" created by the user without too much fuss or changes to the code for other installations of the system.

My working model so far is:

Primary Table
=============
contactid: int
+ a handful of basic fields: username, password, email, etc, mostly all varchar

Custom Fields Table
=============
fieldid: int
fieldtype: varchar (eg. text, dropdown, radiobox)
name: varchar (eg. Cell Phone, Member Status)
values: varchar (eg. if type is a dropdown, lists available options comma seperated: i.e. active,inactive,pending. otherwise, not really used)

Custom Storage
=============
contactid: int (to primary table)
fieldid: int (to custom field table)
value: varchar

The idea is that there would be no limit to the number of fields that could be custom added and each field would get it's own row for each contactid in the table. I realize this table would grow quite large as contacts & custom fields increased. I guess the other option would be to have the Custom Storage table look like:

Custom Storage
=============
contactid : int (to primary)
field1: varchar
field2: varchar
field3: varchar
field4: varchar
field5: varchar
etc.

And have a limited number of custom fields available and each field would just be stored in the appropriate column with only one record in the Custom Storage table per contact. But this would limit the number of custom fields that each installation could make use of (not ideal).

Maybe there is a third option that I'm missing here, or there's an error in my logic.

Also, if my logic is sound for the first proposal, then this is the SQL statement that i would be using to select a contact from the master table and then all the custom fields from the custom storage table:

SELECT
      t1.*,
      t2.value AS field1,
      t3.value AS field2,
      t4.value AS field3,
      etc,
FROM `contacts` AS t1
      LEFT JOIN `custom_storage` AS t2 ON t1.contactid = t2.contactid
      LEFT JOIN `custom_storage` AS t3 ON t1.contactid = t3.contactid
      LEFT JOIN `custom_storage` AS t4 ON t1.contactid = t4.contactid
      etc,
WHERE
      t1.contactid      = 3 AND
      t2.fieldid      = 1 AND
      t3.fieldid      = 2 AND
      t4.fieldid      = 3;

Which seems a little ridiculous, but then again it works, albeit, not tested on a large table. I just can't imagine that my problem or a solution for it is unique, so there must be either a methodology out there or a type of SQL JOIN that I'm missing because as it stands now, I can't wrap my head around solving this problem without an overly complex series of unwieldy SQL statements.Start Free Trial
[+][-]02.28.2008 at 08:05AM PST, ID: 21005091

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MySQL Server
Tags: MySQL, Database, MySQL
Sign Up Now!
Solution Provided By: Nellios
Participating Experts: 1
Solution Grade: A
 
 
[+][-]02.28.2008 at 08:14AM PST, ID: 21005219

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 08:30AM PST, ID: 21005443

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 08:34AM PST, ID: 21005495

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 08:43AM PST, ID: 21005599

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 09:10AM PST, ID: 21005862

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02.28.2008 at 09:41AM PST, ID: 21006188

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.03.2008 at 01:48AM PST, ID: 21030063

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44 / EE_QW_2_20070628