?
Solved

Good practice to store user settings PHP/MySQL

Posted on 2009-12-23
3
Medium Priority
?
1,363 Views
Last Modified: 2013-12-12
I am currently building (a 1001th) community website. I already build the whole interface with hundreds of lines of CSS. Also the relational MySQL database is also build ready in MySQL Workbench.

I set up a fully working multi-language and ActiveRecord CodeIgniter workspace so I'm read-set to go.

I have one last thing I'm pondering about. The user's preferences storing methodic.

I had something like this in the DB structure:

user_preferences
" pref (VARCHAR(45))
" value (TEXT)

I know the methods to store arrays in the a DB-field etc. but I was wondering how others do it. I want to do it DB-wise.

Now I can achieve things like:
$query = mysql_query("SELECT * FROM user_preferences WHERE users_id == $_SESSION['user_id']");

$result = mysql_fetch_assoc($query);

// Some loop through these 2 values to combine them in a logic result
// After collecting all data storing them in a ordered array or object and store it in the SESSION or something like that
$result[0]['pref'];
$result[0]['value'];

Open in new window

0
Comment
Question by:Erwin_001
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
asafadis earned 750 total points
ID: 26118430
Looks fine to me.
I would even dare to say that this is the "industry standard"!

It's the same technique WordPress uses: http://codex.wordpress.org/images/8/83/WP_27_dbsERD.png
Check out the "usermeta" table on the top left.
0
 
LVL 3

Author Comment

by:Erwin_001
ID: 26118522
Nice : ).

I'm having community settings like:

show_dateofbirth (yes, no, friends_only)
show_age
show_profile

etc.

Guess this is satisfactory enough. I works pretty well until now : ). Was just wondering.

Thanks
0
 
LVL 3

Author Closing Comment

by:Erwin_001
ID: 31669678
-
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

831 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