How to create wordpress-like option table and get values for each row?

Posted by Nacho on Stack Overflow See other posts from Stack Overflow or by Nacho
Published on 2010-05-06T19:49:21Z Indexed on 2010/05/07 5:58 UTC
Read the original article Hit count: 186

Filed under:
|
|
|

Hi guys. I'm looking to create an options table in my db that makes every record a system option, so I can work with a little number of fields.

My db has the following structure:

  • 3 columns named id, name, and value

The following data is inserted as an example:

+--+-----------+--------------------------+
|id|name       |value                     |
+--+-----------+--------------------------+
| 1|uri        |www.example.com           |
| 2|sitename   |Working it out            |
| 3|base_folder|/folder1/folder2/         |
| 4|slogan     |Just a slogan for the site|
+--+-----------+--------------------------+

That way I can include a large number of customizable system options very easily.

The problem is that I don't know how to retrieve them. How do I get the value of uri and store it as a var? And better yet, how do I get, for exmaple, values of id 1 and 4 only without making a query each time? (I assume multiple queries are useless and a pretty ugly method.)

I know the question is pretty basic but I'm lost here. I'd really appreciate your answer!

© Stack Overflow or respective owner

Related posts about mysql-query

Related posts about data-structures