MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old May 16th, 2006, 10:14 AM
andrew_wazzup andrew_wazzup is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 3 andrew_wazzup User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 12 sec
Reputation Power: 0
Data in table into an array

Hi, i wonder if anyone can help me.

I have a mysql database which contains a table called "tbl_config" . This table contains two fields, config_name and config_value as shown in the example below. Config_name outlines a series of settings and config_name is the value (both numerical or text) for that setting.

Table - tbl_config

config_name ------ config_value
option_1------ ------1
option_2------ ------0
option_3------ ------main.php

I want to be able to query the database using PHP so that i can get an array so i can access the variables something like this-

PHP Code:
echo $config['option_2']; 


which would echo the value for that setting ie "0".

I'm sure this is fairly simple but i cant work out how to do it and a search on google leads to mainly inserting arrays into a db not the otherway round.

Thanks in advance,

Andrew

Reply With Quote
  #2  
Old May 17th, 2006, 01:27 PM
andrew_wazzup andrew_wazzup is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2006
Posts: 3 andrew_wazzup User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 28 m 12 sec
Reputation Power: 0
Hi, I managed to get this to work but in case anyone else wants to be able to do something similar I shall post the code i've used. I don't know if its the best way of doing it but it works for me!

Data and table structure as outlined above.
PHP Code:
 $query "SELECT * FROM tbl_config ORDER BY config_name asc";
$result mysql_query($query) or die (mysql_error());
$data = array();
$config = array();
while (
$temp mysql_fetch_array($result)) array_push($data$temp);
for (
$i=0;$i<count($data);$i++){
$config[($data[$i]["config_name"])] = $data[$i]["config_value"];


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > Data in table into an array


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway