On Wed, 5 Sep 2001 06:59, Rasmus Lerdorf wrote:
> > In perl I can say something like:
> >
> > ($var1, $var2) = $sqh->fetchrow_array()
> >
> >
> > to assign column values to more than one variable at a time. So I
> > tried similar syntax with PHP:
> >
> >
> > ($var1, $var2) = mysql_fetch_row($sqh);
> >
> >
> > but could not seem to work it out.
> >
> > I know you can do this with a temporary array, and then take values
> > out of the array. But it would be nice to omit the temporary array.
> >
> > Is it possible?
>
> ($var1, $var2) is magic. I hate magic. What do you look up in the
> Perl manual when you hit syntax like that? In PHP the equivalent
> syntax is:
>
> list($var1, $var2) = ...
>
> It does exactly the same thing, and it is legible. Anybody can pop
> over to http://php.net/list and get an explanation of what the code
> does if they run across it.
>
> -Rasmus
Or you can use extract() to provide variable names which match the names
of the fields in your table.
while($row = mysql_fetch_array($sqh));
extract($row);
//do stuff
}
and you don't even have to think up variable names :-)
--
David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc
CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA
I float like an anchor and sting like a moth.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]