SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Already exists code

    Hello, just trying to make my page output user is already online if there name exists in the onlineusers field ive already selected the table anyone jknow the rest of the code?:

    $query = mysql_query("SELECT * FROM onlineusers")
    or die("Could not insert data because ".mysql_error());
    $qry = mysql_fetch_array( $query );
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Mike, are you serious? After all the questions you've been asking in the PHP forum, and after all these months, you still don't know how to write a simple 'if' that confronts a form value with a value extracted from the DB?

  3. #3
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    PHP Code:
    // $username is the username of current user

    $result mysql_query("SELECT
                              `username`
                           FROM
                              `onlineusers`
                           WHERE
                              `username` = '
    $username'")
        or die(
    "Could not insert data because ".mysql_error());

    if (
    mysql_num_rows($result) == 1) {
        
    // user online


  4. #4
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm you sure on that code?
    Animated Chatrooms - www.121chatrooms.net

  5. #5
    Web Professional
    Join Date
    Oct 2008
    Location
    London
    Posts
    862
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I’m sure. Try it before asking and if it doesn’t work then give more details. No need to be so secretive.

    Your code selects all online users. You don’t need to do that if you’re checking for one particular user. My query looks for that specific username—if it returns a row then it means the user is online (is in the onlineusers table, anyway), if it doesn’t then they’re not.

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,509
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Mike, just to state the obvious :
    if the field in your onlineusers table that contains the user id isn't called 'username', then you'll have to change the code decowski posted. Idem if the variable that contains the user id in the script isn't called $username.


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
  •