Results 1 to 2 of 2

Thread: Viewing User Profiles

  1. #1
    Join Date
    Oct 2006
    Posts
    94
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Cool Viewing User Profiles

    Ok, a little hard to explain...

    This is usually found in a forum or a cms. Users have an id number 1,2,3... and forum threads also have an id number. I'm hoping to expand my PHP knowledge a little further! Currently to view someones profile, I have all users listed on a page along with a submit button next to each name which carries a hidden reference to the data in mysql. The submit button's hidden variable is stored as a session variable and passed to a profile.php page which queries the database to retrieve the data for that user.

    Often, when viewing someone's profile say here on Tizag the website address is something like...

    http://forums.tizag.com/member.php?u=6914

    So my question is how do I get my setup to work like that?

    Here's a quick script I put together to work on...

    PHP Code:
    <?php

    mysql_connect
    (localhost,user,password);
    mysql_select_db(database);

    $query "SELECT * FROM users";
    $result mysql_query($query);

    while (
    $row mysql_fetch_array($result)){
    echo 
    '<a href="profile.php?u='.$row['id'].'">'.$row['firstname'].'</a>';
    echo 
    '<br />';
    }
    ?>
    Assuming the above is the correct way to go about this, I still have no clue where to even start with the profile.php page!! If anyone can help that would be great!

    Thanks in advance.

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    It would be something along the lines of the following:

    Code:
    <?php
    mysql_connect(localhost,user,password);
    mysql_select_db(database);
    
    if (isset($_GET['u']) && $_GET['u'] != '') {
     $query = "SELECT * FROM users WHERE `id`=".$_GET['u'];
    
    $result = mysql_query($query);
    
     if (!mysql_num_rows($result)) {
      die('User Not Found');
     }
    
     else {
      echo '<pre>';
      print_r(mysql_fetch_array($result));
      echo '</pre>';
     }
    }
    
    else {
     die('You must enter a user id before continuing');
    }
    ?>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •