|
|
|
|
![]() ![]() |
Feb 24 2007, 09:47 PM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 397 Joined: 9-June 06 From: Wisconsin Member No.: 24,924 |
The extract() function is used in PHP to take an array and split it up into variables. MySQL queries can be parsed this way. Below is an example.
CODE $query = mysql_query("select username, password from users where uid=1"); $result = mysql_fetch_array($query, mysql_assoc); extract($result); print "Your username is : $username"; The extract() function works for ANY array, including $_POST, and $_GET. Makes processing form data a LOT easier |
|
|
|
Feb 24 2007, 10:44 PM
Post
#2
|
|
|
A clever man learns from his own mistakes, a WISE man learns from those of OTHERS ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 975 Joined: 12-April 06 From: Essex, UK Member No.: 21,719 |
I might be able to make use of this, but first, i dont fully understand. Say i had an array like this:
QUOTE $array >>username = shadowx >>password = mypass >>ip = 111.111.111.111 by that i mean that $array['username'] is "shadowx" Now if i were to use EXTRACT would it give me three variables called $username, $password and $ip or do i have to say what i want it to call the variables somehow? |
|
|
|
Feb 24 2007, 11:00 PM
Post
#3
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,993 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
|
|
|
|
Feb 25 2007, 01:57 AM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 397 Joined: 9-June 06 From: Wisconsin Member No.: 24,924 |
You have it right shadowx. It calls the variable names the names of the elements in the array. I would assume it wouldn't work on numerical arrays, but I'm not sure.
|
|
|
|
Feb 25 2007, 01:06 PM
Post
#5
|
|
|
apt-get moo ![]() Group: [MODERATOR] Posts: 2,111 Joined: 28-May 05 From: Hertfordshire, England Member No.: 7,593 ![]() |
It is very useful, but use it with care. People can easily overwrite variables in a string of $_GET variables passed by the browser. You could assign one thing, then they just reassign it at the end. People can also overwrite variables not assigned in the $_GET but that you have been using anyway. Therefore, if you are going to use it, call it before you create any variables (so they have nothing to overwrite) and use the EXTR_SKIP flag to skip any variables that have already been assigned, which stops them tagging them on the end of the address.
|
|
|
|
Feb 25 2007, 03:12 PM
Post
#6
|
|
|
A clever man learns from his own mistakes, a WISE man learns from those of OTHERS ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 975 Joined: 12-April 06 From: Essex, UK Member No.: 21,719 |
You have it right shadowx. It calls the variable names the names of the elements in the array. I would assume it wouldn't work on numerical arrays, but I'm not sure. humm this could be useful to me in the case! i always find it so tedious to sit and write 5 lines of assigning variables from a POST array. Thanks for the info! |
|
|
|
Mar 27 2007, 11:54 PM
Post
#7
|
|
|
Advanced Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 144 Joined: 22-March 07 Member No.: 40,472 |
wow thanx for the tip
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 5th September 2008 - 11:58 PM |