Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Typing in ID showing Username

    Hi, I am making a friends list on my website, and when you put in a friends ID number, it adds it to the list. But (of course) it shows the ID. I would like it to change the ID to the persons name.

    Here is some of what I have coded, maybe someone can figure out how to check users to match ID?

    Code:
    if (isset($_POST["submit"])) {
          $id=$_POST['id'];
          $id=strip_tags($id);
       
     if ($userrow["friend1"] == "None") {
           $page = "<table width='100%'><tr><td class='title'>Add New Friends</td></tr></table>";
         $page .= "<center><font color=lightgray><b>Fayt:</b> You have added 
    Player ID $id to your friends list.<br /><br />";
         $page .= "You can return to <a href=\"index.php\">Town</a></font></center><p>";
           $updatequery = doquery("UPDATE {{table}} SET friend1='$id' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
         }
    
    
     else {
        $updatequery = doquery("UPDATE {{table}} SET location='Friends List' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
            $title = "Friends List";
            $page = "<table width='100%' border='1'><tr><td class='title'>Add New Friends</td></tr></table><p>";
            $page .= "<center><font color=lightgray><b>Welcome to your friends list!</b><br /><br />";
            $page .= "You currently have the following friends:</font><br /><br />";
            $page .= "<font color=white><b>Friend 1:</b> ".$userrow["friend1"]."</font><br />";
    
    $page .= "<form action=\"friends.php?do=main\" method=\"post\">";
            $page .= "<input type=\"text\" name=\"id\" value=\"ID\" /> <input type=\"submit\" name=\"submit\" value=\"Add Friend\" /></form><br /><br /><br />";
    
    display($page, $title);
    
    }

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    SELECT `username` FROM `users` WHERE `id` = $id

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    So make it like this?

    Code:
    $query = doquery("SELECT username FROM {{table}} WHERE id='$id' LIMIT 1", "users");
    and how would I call that? Meaning how do I get the username to come up in the friend 1 spot instead of a number?

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by masterofollies View Post
    So make it like this?
    Yep.
    Quote Originally Posted by masterofollies View Post
    and how would I call that? Meaning how do I get the username to come up in the friend 1 spot instead of a number?
    I have no idea.. you're using a non-standard function for the query. Normally you would use mysql_query() to execute the query, and mysql_result() or mysql_fetch_*() to get the row's fields.

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Hmm this is going to take alot of thinking to figure out...


  •  

    Posting Permissions

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