Displaying another users' profile [closed]
I have developed a php file called "profile.php" that displays the current user's profile.But, I could not decide how to display others' profile pages. I mean, for example, i displayed all of the members on the main page and clicked one of them. Then, should i use "a href" tag for every user to direct to another php file, for instance, another_profile.php . If so, How can i send the clicked user's information, name, surname etc. ,to the another_profile.php? Thanks
try GET variable...
<a href = "profile.php?profile_id=1">Check out the profile!</a>
Next catch the profile_id query string $id = $_GET['profile_id']
and find the id (1 in this case) in your database to get the data that belongs to that profile.
I hope it helps.
Somehow your profile has to accept a GET parameter, for example id. That should be the Id you request to the database, instead of the current user's id.
Your page might look like this:
if(isset($_GET['id']) && is_numeric($_GET['id'])) //Is there an ID parameter, and is it numeric?
$id = $_GET['id']; //There was a user id in the url (profile.php?id=1)
else
$id = $_SESSION['user_id']; //No id specified, get the current user's id. You need to change this to your own session key.
Then use your $id
value to get all the information you need, for example:
$userInfo = mysql_query("SELECT firstname, lastname, etc, etc FROM user WHERE id = $id");
精彩评论