Re: question
| From: | Dan Fitzpatrick | Date: | Wed, 12 Dec 2001 22:31:29 +0000 |
| Subject: | Re: question | ||
| References: | 1 2 3 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-14978@lists.php.net to get a copy of this message | ||
Robert,
The easiest way to convert result set values to the field variable names
is with one line of code:
extract(mysql_fetch_array($row));
This will set $firstname = $row["firstname"], etc.
Dan
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dan Fitzpatrick
Overhaul Search
http://www.overhaulsearch.com
mailto:dan@overhaulsearch.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Robert Weeks wrote:
>
> Hi,
>
> I'm a little stumped here, maybe I haven't had enough coffee yet.......
>
> Anyway, I have a lot of SQL queries that return one row if there is a match
> and instead of having to write out something like this:
>
> $firstname = $row["firstname"];
> $lastname = $row["lastname"];
> $midinitial = $row["midinitial"];
> $preferredname = $row["preferredname"];
> $address1 = $row["address1"];
> $address2 = $row["address2"];
> $city = $row["city"];
> $state = $row["state"];
> $zip = $row["zip"];
>
> I thought I'd loop through the result and and get the info out like this:
>
> $nrows = mysql_num_rows($result);
> $nfields = mysql_num_fields($result);
> $rowarray = mysql_fetch_row($result);
>
> for ($i=0; $i<$nfields; $i++){
> $fname = mysql_fieldname($result,$i);
> $val = $rowarray[$i];
> $fname = $val;
> }
>
> and then later in the page reference the values using <?=$address1?>
>
> Problem is this isn't working. If I echo the varibles to the page they will
> print out but they wont show up in the <?=$address1?> tags.
>
> I tried setting the varibles to global and that still doesn't seem to work.
> I know I'm missing something really simple and basic here. If someone could
> give me a push in the right direction I'd appreciate it.
>
> Thanks,
>
> Robert