I'm trying to create a user profile page. The user selects whose profile he wants to view based on a search. By clicking a "view profile" button the page should then go to profile.php where it displays the user's profile.

For now, I'm just trying to test it out and only display the user's name. Here's the code I have.

My problem is that I don't know how to pass "$userID" to profile.php which will then be used to look up that user's information. Since the value is in a while loop, I'm not sure how to select for once instance of this loop.

```
 function findUsers($friend){
    $search = mysql_query("Select * from users where username='$friend'");
            $userLocation = mysql_query("select * from userinfo where    username='$friend'");
            $locationResult = mysql_fetch_array($userLocation);
            $locationResultArray = $locationResult['userlocation'];
            $locationExplode = explode("~","$locationResultArray");

            //table column names
            echo "<table>";
            echo "<tr><td>";
            echo "Username";
            echo "</td><td>";
            echo "Location";
            echo "</td></td><tr><td>";
                while($result = mysql_fetch_array($search)) //loop to display search
                { 
                       $userID = $result['userid']; //can I pass this value to the function since it's possible that there is more than 1 userID from the while loop?
                    echo $result['username'];
                    echo "</td><td>";
                    echo $locationExplode['0'];
                    echo ", ";
                    echo $locationExplode['1'];
                    echo "</td><td>";
                ?>
                    <form method="post" action="profile.php">
                <?
                    echo "<input type='submit' name='profile' value='View User's Info'";
                    echo "</td><td>";
                ?>
                    </form>
                    <form method="post" action="profile.php">
                <?
                    echo "<input type='submit' name='addfriend' value='Add Friend' />"; //code still needs to be written for this input.
                    echo "</td></tr>";
            }
                    echo "</table>";
            if(isset($_POST['profile'])){
                $viewProfile->displayProfile($userID); //This is where I'm not sure if it's taking the correct userID.
            }
        }
}
 ?>

```

...and the page to display the profile

```
<?
 include_once 'infoprocesses.php';
 $user = new dbProcessing();

Class viewProfile{
function displayProfile($username){ //display profile pulls the user's name from the databse
    echo $username; //used to test if value is being sent...nothing is being displayed
    ?>
    <h2><?php $user->username($username);?>'s Information</h2>
    <?
    }
}
?>

```