Welcome Guest, Not a member yet? Register   Sign In
Grabbing options from DB
#1

[eluser]naez[/eluser]
I have some options stored away in a DB.

DB structure:

id -> option_name -> option_value


Now in my model I have this:

Code:
function getOptions()
    {
        $options = array();
        $this->db->select("option_name, option_value");
        $res = $this->db->get('options');
        foreach($res->result() as $key => $val)
        {
                $options[$key] = $val;
        }
        die(print_r($options));
        // return $options;
    }

The only problem is when I print_r the array, its wayyyyyy to multi-dimensional.

I'm new to codeigniter so I'm not sure the right way to do this.

Thanks for helping =p


Edit:

now I have

Code:
function getOptions()
    {
        $options = array();
        $this->db->select("option_name, option_value");
        $res = $this->db->get('options');
        foreach($res->result() as $val)
        {
                $options[$val->option_name] = $val->option_value;
        }
        die(print_r($options));
        // return $options;
    }

which gives me

Array ( [site_name] =>
Sitnamehere
[site_slogan] => mysiteslogan ) 1

I'm not sure whats up with the 1 at the end however.




Theme © iAndrew 2016 - Forum software by © MyBB