Welcome Guest, Not a member yet? Register   Sign In
Storing User Preferences & Site Preferences
#11

[eluser]skunkbad[/eluser]
I think the real solution for you might be to serialize arrays of preferences into groups, and insert them in the database as serialized. When you query the database, simply unserialize the data in the group, and you have access to your array of prefs.
#12

[eluser]tomcode[/eluser]
Quote:to serialize arrays of preferences into groups

a nice one, only drawback is You loose db specific funtionality (sorting, selecting)
#13

[eluser]jedd[/eluser]
Note that if you have two tables, where the sets of data in each table are totally reliant on the same PK, then you're doing it wrong. If you're heading down this path, then the point of a 'user prefs' table is pretty much lost. You should simply migrate your preferences into additional columns of your user table and let go of the separate prefs table.

And indeed that's how I do it with my user table - there's a bunch of BOOL columns for things that every user has one and only one choice about, or setting for.

Future changes will necessitate an additional column, but this is no big deal. Compared to the additional code needed to handle the settings and interpretation of a new setting it's pretty trivial. If you want to get smart about how you handle the user configuration page, you could have all your prefs prefixed with pref_ or similar. I forget who, but someone in a recent discussion about table design suggested all their bools start with is_, which might be another approach. This would let you progammatically deal with all is_ or pref_ columns with a loop in your form - but you'd still obviously need more sophisticated code changes to deal with the affects of that setting.
#14

[eluser]Zack Kitzmiller[/eluser]
[quote author="tomcode" date="1245584095"]
Quote:to serialize arrays of preferences into groups

a nice one, only drawback is You loose db specific funtionality (sorting, selecting)[/quote]

Actually.. There is one set of preferences that this would work really well for, stuff that is required.

The option preferences wouldn't work though, cause I need to select all people, that haven't set a preference for somethings..

Any other idea?
#15

[eluser]skunkbad[/eluser]
[quote author="jedd" date="1245600657"]Note that if you have two tables, where the sets of data in each table are totally reliant on the same PK, then you're doing it wrong. If you're heading down this path, then the point of a 'user prefs' table is pretty much lost. You should simply migrate your preferences into additional columns of your user table and let go of the separate prefs table.

And indeed that's how I do it with my user table - there's a bunch of BOOL columns for things that every user has one and only one choice about, or setting for.

Future changes will necessitate an additional column, but this is no big deal. Compared to the additional code needed to handle the settings and interpretation of a new setting it's pretty trivial. If you want to get smart about how you handle the user configuration page, you could have all your prefs prefixed with pref_ or similar. I forget who, but someone in a recent discussion about table design suggested all their bools start with is_, which might be another approach. This would let you progammatically deal with all is_ or pref_ columns with a loop in your form - but you'd still obviously need more sophisticated code changes to deal with the affects of that setting.[/quote]

I somewhat agree about the choice of having the same PK in two tables being wrong, but the reason why I do this in my own database is so that there is a core table for authentication, and if there are account details per user (which may change from site to site), then they reside in the second table. Sure, the core user table could be modified, but it was just my way of thinking (which is the way I like it!).
#16

[eluser]tomcode[/eluser]
Quote:The option preferences wouldn’t work though, cause I need to select all people, that haven’t set a preference for somethings..

Any other idea?

Well, I guess You end up with plain tables, either one or two. I'd test the two solutions for speed (indexes !).




Theme © iAndrew 2016 - Forum software by © MyBB