View Full Version : db rows into array

04-03-2007, 12:34 AM
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.

04-03-2007, 12:35 AM
fetch_array already puts them into an array.

04-03-2007, 12:56 AM
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"

04-03-2007, 01:09 AM
Apparently this is for configuration values obviously.

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

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

echo $config['site_name'];

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



04-03-2007, 01:13 AM
heh, thanks. I knew it was simple, but I guess I just wasnt thinking.

04-03-2007, 02:18 AM
Your welcome :)