Get settings from database

PythonPython Forum LeaderThe Royal RAM
I want to extract some values from a table in PHP and MySql but not quite sure on how to do it.

The table contains two columns:
config_name || config_value

Example data is:
status || 1
maxview || loads
something || avalue

I need to get it somehow so that I could do things like:

if($settings[status]==1){
// do something
}

if($settings[maxview]=="loads"){
// do something
}


How is this done. Ive done it before but cant remember how.

The Royal Ram

Comments

  • martian2k4martian2k4 Llama Hunter Moderator
    Do you want it so if $settings[status]==1 and $settings[maxview]=="loads" it does somthing?

    If this is what you want to do you have to put

    if($settings[status] == 1 && $settings[maxview] == 'loads'){

    // Do sommat here

    }

    :D
    Free MySpace Layouts- Coming soon
    Photoshop Tutorials- Coming soon
    Premium PHP Scripts- Coming soon

    Haha i should really do some work so i can remove all the coming soon's
  • ChroderChroder Senior Member The Royal RAM
    Just do a query to fetch the settings, then loop through the results and built a new array as you go along.

    [php]$res = mysql_query("SELECT * FROM config");

    $settings = array(); // our new array


    //
    // Build array
    //
    while($item = mysql_fetch_array($settings))
    {
    // Use the config_name as
    // the $settings index key
    $settings[ $item ] = $item;
    }


    //
    // Use the values
    //
    if($settings == 1)
    {
    // ...
    }

    if($settings == 'loads')
    {
    // ...
    }[/php]
  • PythonPython Forum Leader The Royal RAM
    yeah thanks for that :)

    I figured it out yesterday :)

    Thanks for your help anyway

    The Royal Ram

Sign In or Register to comment.