making "list" vars global

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vertige
Forum Newbie
Posts: 3
Joined: Thu May 16, 2002 3:18 pm

making "list" vars global

Post 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))
{
}
daholygoat
Forum Newbie
Posts: 1
Joined: Thu May 16, 2002 4:42 pm

Post 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.
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post 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
Post Reply