Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post

    db rows into array

    Im sure this is simple, but I cant seem to visualize how this would happen.

    I have a table in my db with three cols: id, key, value.

    What I want to do is be able to call these things from something like:

    $config[key] = value

    I think i need to do a while loop through all the results, but im not exactly sure.

  • #2
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    fetch_array already puts them into an array.

  • #3
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    fetch_array only does it for one row though.

    here is an example:

    ID Key Value
    1 site_name Test Site
    2 logo logo.jpg
    If I do a fetch array on a query like: SELECT * FROM tablename

    And did $array['key'] I would get either site_name or logo.

    I want to be able to do $arrayorsomething['site_name'] and get "Test Site" and if i do $arrayorsomething['logo'] i want to get "logo.jpg"

  • #4
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Apparently this is for configuration values obviously.

    You can setup a new array with the while statement or just assigned them as defines.

    PHP Code:
    while($row fetch array) {
       
    $config[$row['key']] = $row['value'];
    }

    echo 
    $config['site_name'];
    //or

    while($row fetch array) {
        
    define(uppercase($row['key']), $row['value']);
    }

    echo 
    SITE_NAME

  • #5
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    heh, thanks. I knew it was simple, but I guess I just wasnt thinking.

  • #6
    Regular Coder
    Join Date
    Oct 2005
    Location
    Right Here
    Posts
    654
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Your welcome


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •