Cross89 Posted November 21, 2009 Share Posted November 21, 2009 Hello, I'm building a blog software for giggles, and I have a table in my database that stores configuration information in a manner such as this: id option_name option_value 1 site_title My Blog Site 2 site_slogan Its a blog site; didn't you know? 3 admin_email admin@email.com etc. What I want to do is have a SQL query run when a page is loaded that takes this information and implements it on the page - so the header is populated with the title and slogan, etc. What I am having trouble with is trying to do this with one query. It'd be very taxing to have to run 20 queries before the page is even rendered. So does anyone know how I can easily access the information so it can be deployed easily across pages? I hope this is enough information. Thanks, Matt Quote Link to comment https://forums.phpfreaks.com/topic/182356-solved-efficent-way-of-grabbing-sql-entries/ Share on other sites More sharing options...
Alex Posted November 21, 2009 Share Posted November 21, 2009 Something like this should do (Just make sure you replace the table name with your own): $result = mysql_query("SELECT option_name, option_value FROM table"); while($row = mysql_fetch_assoc($result)) { $config[$row['option_name']] = $row['option_value']; } You can then access your configuration details in the associative array $config like such: $config['site_title'], $config['site_slogan'], etc.. Quote Link to comment https://forums.phpfreaks.com/topic/182356-solved-efficent-way-of-grabbing-sql-entries/#findComment-962311 Share on other sites More sharing options...
Cross89 Posted November 21, 2009 Author Share Posted November 21, 2009 Oh I feel so stupid now, haha. I guess I had a coder's block or something! Thanks a lot for the help. Quote Link to comment https://forums.phpfreaks.com/topic/182356-solved-efficent-way-of-grabbing-sql-entries/#findComment-962312 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.