Jump to content

Site Options Table


rawrtiger

Recommended Posts

I'd like to have a table that has all my site options in it (eg. Site Name, Site URL, etc.) and then an easy way to define variables from it in PHP.

 

I currently have the table structured like so:

ID _|_ Setting _|_ Value
1   |  setting1 |   a
2   |  setting2 |   b
3   |  setting3 |   c
4   |  setting4 |   d

 

I'd like a file that will select each value and define it as a variable in PHP so I can use the variables in my other files. This is what I'm doing for now but it's not a very good way to do it:

 

$result = mysql_query("SELECT * FROM config WHERE site_option = 'setting1'");
while($row = mysql_fetch_array($result)) {
$pagetitle = $row['value'];
}
$result = mysql_query("SELECT * FROM config WHERE site_option = 'setting2'");
while($row = mysql_fetch_array($result)) {
$siteurl = $row['value'];
}

 

What would be a better way to do it?

Link to comment
Share on other sites

Just store them all in an array.

 

<?php

$config = array();
if ($result = mysql_query("SELECT Setting, Value FROM config")) {
    if (mysql_num_rows($result)) {
        while ($row = mysql_fetch_array($result)) {
            $config[$row['Setting']] = $row['Value'];
        }
    }
}

 

Now that $config array holds all your settings.

Link to comment
Share on other sites

Just store them all in an array.

 

<?php

$config = array();
if ($result = mysql_query("SELECT Setting, Value FROM config")) {
    if (mysql_num_rows($result)) {
        while ($row = mysql_fetch_array($result)) {
            $config[$row['Setting']] = $row['Value'];
        }
    }
}

 

Now that $config array holds all your settings.

Thank you!

Link to comment
Share on other sites

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.