thesavior
04-02-2007, 11:34 PM
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.
iLLin
04-02-2007, 11:35 PM
fetch_array already puts them into an array.
thesavior
04-02-2007, 11:56 PM
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"
iLLin
04-03-2007, 12: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'];
//or
while($row = fetch array) {
define(uppercase($row['key']), $row['value']);
}
echo SITE_NAME;
:)
thesavior
04-03-2007, 12:13 AM
heh, thanks. I knew it was simple, but I guess I just wasnt thinking.