SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard GoldFire's Avatar
    Join Date
    Oct 2002
    Location
    Oklahoma City, OK
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Problem With Users Onine Script!

    I have a script that is suppost to show the # of online users. I have the following code included in all of my pages to insert the current time into the db:

    PHP Code:
      <? $update mysql_query("INSERT INTO tblUsers SET visit = NOW()"); ?>
    And the code to show the # of online is:

    PHP Code:
    include ("preferences.inc.php");

    $sql "SELECT username, visit FROM tblUsers WHERE UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(visit) <= 300";
    $active_users mysql_query($sql);
    $numberusers = @mysql_num_rows($active_users);
    if (
    $numberusers == 0) {
        echo (
    "Online User = 0");
    }
    else {
        if (
    $numberusers == 1) {
            echo (
    "Online Users =  $numberusers<br><br>");
        }
        else {
            echo (
    "Online Users =  $numberusers<br><br>");
        }
    }
        
    $sql "SELECT username, visit FROM tblUsers WHERE UNIX_TIMESTAMP( NOW() ) - UNIX_TIMESTAMP(visit) <= 300";
    $active_users mysql_query($sql);
    $count 1;
    while (
    $active = @mysql_fetch_array($active_users)) {
        if (
    $count == 1) {
            echo (
    '<a href="" class="nav">'.$active["user"].'</a>');
        }
        else {
            echo (
    " , <a href=\"\" class=\"nav\">".$active["user"]."</a>");
        }
        
    $count++;

    I have tested it and I am on and my friend is on at the same time, but it always says Users Online = 0. Also when I inserted the time to test if the script worked it didn't show anything except for ,
    Last edited by schooglepets; Dec 23, 2002 at 14:25.

  2. #2
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know if this solves all the problems, but you need to change $active["user"] to $active["username"] to match your SQL statement.
    Paul Davey
    webmaster for Whitford Church of Christ


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
  •