Column names into variables

Column names into variables

am 26.07.2006 19:14:52 von z

------=_Part_23156_12950961.1153934092968
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Hi,

I have a table with about 50 columns in it. I'd like to query the
information for one record, and hold the data in variables that have the
same name as the column headings, along these lines:

$query = "Select * from `postings` where `id` = $userid";
$result = mysql_query($query);
while($row=mysql_fetch_array($result)) {
$id = $row["id"];
$location = $row["location"];
$employer = $row["employer"];
...
}

I'd like to do this for all columns in the table, and feel like there's a
way to do this automatically, but haven't been able to find the function or
syntax to use. Any help is greatly appreciated.

Thanks,
Zeth

------=_Part_23156_12950961.1153934092968--

Re: Column names into variables

am 26.07.2006 21:04:40 von Ben Hatfield

I believe this does exactly what you want.

http://us3.php.net/extract

Ben Hatfield
Programmer
ben@soapboxstudio.com

Soapbox Studio, Inc.
469 N. Lake Street
Mundelein, IL 60060
P: +1.847.566.0666 x6#
www.soapboxstudio.com


On Jul 26, 2006, at 12:14 pm, z wrote:

> Hi,
>
> I have a table with about 50 columns in it. I'd like to query the
> information for one record, and hold the data in variables that
> have the
> same name as the column headings, along these lines:
>
> $query = "Select * from `postings` where `id` = $userid";
> $result = mysql_query($query);
> while($row=mysql_fetch_array($result)) {
> $id = $row["id"];
> $location = $row["location"];
> $employer = $row["employer"];
> ...
> }
>
> I'd like to do this for all columns in the table, and feel like
> there's a
> way to do this automatically, but haven't been able to find the
> function or
> syntax to use. Any help is greatly appreciated.
>
> Thanks,
> Zeth

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php