Jump to content

Recommended Posts

Hello,

 

I'm building a blog software for giggles, and I have a table in my database that stores configuration information in a manner such as this:

 

id    option_name    option_value

1      site_title          My Blog Site

2      site_slogan      Its a blog site; didn't you know?

3      admin_email    admin@email.com

 

etc.

 

What I want to do is have a SQL query run when a page is loaded that takes this information and implements it on the page - so the header is populated with the title and slogan, etc.

 

What I am having trouble with is trying to do this with one query. It'd be very taxing to have to run 20 queries before the page is even rendered. So does anyone know how I can easily access the information so it can be deployed easily across pages?

 

I hope this is enough information.

 

Thanks,

Matt

Something like this should do (Just make sure you replace the table name with your own):

 

$result = mysql_query("SELECT option_name, option_value FROM table");
while($row = mysql_fetch_assoc($result))
{
     $config[$row['option_name']] = $row['option_value'];
}

 

You can then access your configuration details in the associative array $config like such: $config['site_title'], $config['site_slogan'], etc..

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.