Help! I need to display user details on page

They have: 105 posts

Joined: Mar 2006

I am making a user managment website, currently users can browse members and view their own profile.

How can I make it so that if a user clicks on a username displayed in the browse members page it takes them to a page which changes the information displayed (username, location etc) depending on what user you clicked on in the browse members page?

Is it something like this (in the browse members page)?

Username

Once this has been clicked, what do I put in the profile.php page to get the information for that username?

If you know how to do this please help! Wink

He has: 698 posts

Joined: Jul 2005

I assume you are using MySQL for your database needs.

The link is correct, and then the profile page would look something like this, with your own modifications depending on your columns and design-related changes:

<?
//insert mysql connect information
$userName = $_GET['username'];
//Stores the username that was transferred via the URL you provided for use later

$getUser = mysql_query("SELECT * FROM users WHERE username = '$userName'");
//Selects all rows with the specified username (there should always be no more than one)
$numUser = mysql_num_rows($getUser);
//This gets the number of rows that the previous variable has found (this is for testing on the next line
echo "<table>";
if($numUser) {
  while($row = mysql_fetch_array($getUser)) {
    echo "<tr><th>";
    echo $row['userName'];
    echo "</th></tr>";
    echo "<tr><td><b>Location: </b></td><td>";
    echo $row['userLocation'];
    echo "</td></tr>";
  }
echo "</table>";
}
else {
echo "That username does not exist.";
//Provides a page if a user tries to insert a wacky username that doesn't exist.
'

I don't advocate the use of tables at all, but this gives you some sample code for how to display user data depending on what your field (column) names are.

Kurtis

greg's picture

He has: 1,581 posts

Joined: Nov 2005

mscreashuns;221488 wrote: ......The link is correct, .......

wouldn't an id of some sort need to be assigned to the url data being sent by the link?

Username

would be

Username

so user=username
then

$userName = $_GET['user'];

so the variable $userName would be assigned to the value of "username"

I am asking becasue I dont know
And to use the direct method you suggested will save time if I ever need it in the future

He has: 698 posts

Joined: Jul 2005

Yeah, greg, you are correct. I misread the link originally posted.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.