My blog has moved!

You should be automatically redirected in 2 seconds. If not, visit
http://www.programmersmind.com/blog/
and update your bookmarks.

Friday, July 7, 2006

An easy way to loop through db records

As I was finalizing some tweaks to a social networking script for a client, I noticed an interesting way that variables are pulled off the db record set which I didn't know of previously.

extract((array)$row,EXTR_PREFIX_ALL,"row");

This takes all the variables within the $row array, which I would typically access by $row[varname] and creates a variable called $row_varname. Pretty neat!

I had previously done something similar to this by looping through the array and assiging $GLOBALS[varname] = $value, but this neat little sucker does all that for us, now doesn't it!

No comments:

Friday, July 7, 2006

An easy way to loop through db records

As I was finalizing some tweaks to a social networking script for a client, I noticed an interesting way that variables are pulled off the db record set which I didn't know of previously.

extract((array)$row,EXTR_PREFIX_ALL,"row");

This takes all the variables within the $row array, which I would typically access by $row[varname] and creates a variable called $row_varname. Pretty neat!

I had previously done something similar to this by looping through the array and assiging $GLOBALS[varname] = $value, but this neat little sucker does all that for us, now doesn't it!

No comments: