PDA

View Full Version : Sql Array


pchl1990
07-12-2008, 11:04 PM
Hello

I have a tabel named config
in that table there is 2 rows, name and value.

===========================
| name | value |
===========================
| color | red |
---------------------------
| webname | webpage|
---------------------------
| version | 1.0 |
---------------------------


in my phpcode:


$configrow = sql_query("SELECT * FROM config");
$configarr = mysql_fetch_array($configrow);


How can i get the "value" into my php?
$cofingarr['webname']

this is not working :(
how can i make my output to be the value?

rafiki
07-12-2008, 11:26 PM
Hello

I have a tabel named config
in that table there is 2 rows, name and value.

===========================
| name | value |
===========================
| color | red |
---------------------------
| webname | webpage|
---------------------------
| version | 1.0 |
---------------------------


in my phpcode:


$configrow = sql_query("SELECT * FROM config");
$configarr = mysql_fetch_array($configrow);


How can i get the "value" into my php?
$cofingarr['webname']

this is not working :(
how can i make my output to be the value?
You got a typo....
echo $configarr['webname'];

pchl1990
07-13-2008, 12:00 AM
You got a typo....
echo $configarr['webname'];

Sure, my mistake.
but still it does not work :(

rafiki
07-13-2008, 12:05 AM
Are you sure you are connecting to the database correctly?
Are you sure your selecting the database correctly?
Use $configrow = mysql_query("SELECT * FROM config") or die(mysql_error());
instead of sql_query()

dumpfi
07-13-2008, 09:00 AM
You must first build a hashtable out of the data:

$configrow = sql_query('SELECT `config`.`name`, `config`.`value` FROM config');
$configarr = array();
while($r = mysql_fetch_row($configrow)) // or use mysql_fetch_assoc for better readability
{
$configarr[$r[0]] = $r[1];
}
echo $configarr['webname']; // echos "webpage"
dumpfi

pchl1990
07-13-2008, 12:58 PM
Sure, my mistake.
but still it does not work :(

You got a typo....
echo $configarr['webname'];

Thanks very mutch :)
It worked :thumbsup:

rafiki
07-13-2008, 08:36 PM
So dumfi gets my thanks? Hmmm...

pchl1990
07-14-2008, 07:43 PM
So dumfi gets my thanks? Hmmm...

huh?
You mean?