Page 1 of 1

making "list" vars global

Posted: Thu May 16, 2002 3:18 pm
by vertige
I am trying to make the list elements ($user_id, $user_username,) global so i can acccess them in the rest of my code further down in the page.

How do you take the elements of an array and make them global?

here is the code:$resultID = mysql_query("Select * from user_access", $linkID);

while (list ($user_id, $user_username, $user_password, $user_fname, $user_lname, $user_access, $user_email) = mysql_fetch_row($resultID))
{
}

Posted: Thu May 16, 2002 4:42 pm
by daholygoat
Well there's a bit more to it. When you're using the list() inside the while(), logically the variables get re-initiated after every loop sequence, thus they will be lost at the end of the block anyway. What you could do however is creating an array before the loop, and read the seperate variables that are a result from list() into the array while looping. That way the array is filled after the loop invoked.

Posted: Thu May 16, 2002 5:08 pm
by sam

Code: Select all

$i = 0;
while (list ($user_idї$i], $user_usernameї$i], $user_passwordї$i], $user_fnameї$i], $user_lnameї$i], $user_accessї$i], $user_emailї$i]) = mysql_fetch_row($resultID)){ 
$i++;
}
Cheers Moe