Good practice to store user settings PHP/MySQL

Posted on 2009-12-23
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:

" 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

Open in new window

Question by:Erwin_001
    LVL 11

    Accepted Solution

    Looks fine to me.
    I would even dare to say that this is the "industry standard"!

    It's the same technique WordPress uses:
    Check out the "usermeta" table on the top left.
    LVL 3

    Author Comment

    Nice : ).

    I'm having community settings like:

    show_dateofbirth (yes, no, friends_only)


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

    LVL 3

    Author Closing Comment


    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now