Page 1 of 1

Select all fields and add to an array?

Posted: Thu Aug 04, 2005 1:00 pm
by ny
Hi,

I have got a mysql table which cols are changing (bad i know...)

i want to select all cols and add them to an array

aka
$dbquery['col'] => value

any way to do this?

Posted: Thu Aug 04, 2005 1:05 pm
by anjanesh
You want to get all the field (column) names of the table or all rows of a particular field (column) ?

Posted: Thu Aug 04, 2005 1:28 pm
by ny
i want an named (indexed?) array...

i want to get values of the array via $array['colname'] = $calvalue

Sorry, but my englis his terrible hope you understand ;)

Posted: Thu Aug 04, 2005 2:14 pm
by anjanesh

Code: Select all

$arr = array();
$Sql = "SELECT `field1` FROM `table1`";
$Res = mysql_query($Sql);
while ($Row = mysql_fetch_assoc($Res))
 {
        $arr[] = $Row['field1'];
 }