Re: Strange anomolie with each() and mysql_fetch_array()

From: Date: Fri, 24 Jan 2003 14:19:06 +0000
Subject: Re: Strange anomolie with each() and mysql_fetch_array()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-132991@lists.php.net to get a copy of this message
> Because that magic incantation that Rasmus taught me many years ago will > take every field/column of the returned database row and make a variable > named the same thing with the corresponding value Use this (damned sight easier): extract($row) ----- Original Message ----- From: "Daevid Vincent" <daevid@daevid.com> To: "'Rick Emery'" <remery@emeryloftus.com>; <php-general@lists.php.net> Sent: Friday, January 24, 2003 7:46 AM Subject: RE: [PHP] Strange anomolie with each() and mysql_fetch_array() > First, if you expect only a single row returned, why are you > using a while(){} construct? > Third, each() operates on succeeding elements of an array; > there are only two elements aparrently, > so what are you expecting each() to do? Because that magic incantation that Rasmus taught me many years ago will take every field/column of the returned database row and make a variable named the same thing with the corresponding value. So, for example, I will get $customer_id = 5, $customer_name = "Joe Blow", etc... And when you have a pant load of fields in one row, it comes in very very handy. > Second, mysql_fetch_array() does not like to operate within > another function call. I've tried it on > multiple occasions; failed. That seems like a bug to me then. Hence the reason I bring it up. Seems to me there is no reason the second statement shouldn't work just as the first. > ----- Original Message ----- > From: "Daevid Vincent" <daevid@daevid.com> > To: <php-general@lists.php.net> > Sent: Thursday, January 23, 2003 11:38 PM > Subject: [PHP] Strange anomolie with each() and mysql_fetch_array() > > > How come I *can* do these commands: > > $row = mysql_fetch_array($result,MYSQL_ASSOC); > while(list($myVariableName,$sqlFieldName)=each($row)) > { $$myVariableName = $sqlFieldName; } > > But I can't do this command? > > > while(list($myVariableName,$sqlFieldName)=each(mysql_fetch_arr > ay($result > ,MYSQL_ASSOC))) > { $$myVariableName = $sqlFieldName; } > > Notice the only differenceis that the first one assigns the array to > $row FIRST, whereas the second tries to avoid that extra call, > especially since I know I'm only getting one row back. Hmmm? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#132991) next »