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
    New to the CF scene
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    website users online script??

    i have wrote a script that should show the users online on my website and it comes up with "Query was empty" when i open the pages that it is included on. Even when i log into the website it doesnt show on the users online.

    This is the code that i have for updating the users last active time

    PHP Code:
        if ( $login_username_num == )
        {
            
    $login_password_sql "SELECT user_username FROM noobsonline_users WHERE user_username='$_POST[f_username]' AND user_password=md5('$_POST[f_password]')";
            
    $login_password_result mysql_query($login_password_sql)
                or die (
    "Couldnt Execute login_password Query");
            
    $login_password_num mysql_num_rows($login_password_result);
            if ( 
    $login_password_num )
            {
                
    $_SESSION['wOOtwOOt'] = "YEAH";
                
    $login_username $_POST['f_username'];
                
    $_SESSION['login_username'] = $login_username;
                
    $today date("Y-m-d H:m:s");
                
    $lastaction_sql "UPDATE noobsonline_users SET user_lastaction='$today' WHERE user_username='$_SESSION[login_username]'";
                
    mysql_query($lastaction_sql)
                    or die (
    "couldn't Update Last Action");
                
    header("Location: index.php?page=usercp");
            }
            else 
    and this is the code that i have to select the users online from the database. If ainone could help me out with this it would be much apreciated. As i have looked nearly everywhere and cant find anything that has helped me as of yet

    PHP Code:
    <?php
    echo"<span class='Sheading'>Users Online</span><br /><br />
        Users Online is based on the active users in the last five minutes<br /><br />"
    ;
    $fivemin_ago mktime(date("H"), date("i")-5date("s"), date("m"), date("d"), date("Y"));
    $fivemin_ago_ts date("YmdHis"$fivemin_ago);
    $online_sql "SELECT user_ID,user_username,user_status FROM noobsonline_users WHERE user_lastaction > $fivemin_ago_ts";
    $online_result mysql_query($sql)
        or die(
    mysql_error());
    while (
    $row mysql_fetch_array($result))
    {
        
    extract($row);
        echo
    "<a href='index.php?page=profile&userid=$user_ID'>$user_username</a> ";
        if ( 
    $counter == )
        {
            echo
    "";
        }
        
    $counter++;
    }
    echo
    "<br /><br />";
    ?>
    Also if it was at all possible i would like the site to be viewed in GMT 0 as that is my time zone and would like the site to go by it. if that can be done even better

    Thanks in advance

    Andy

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Be sure to surrond your field and table names in backticks, like this:

    PHP Code:
    $online_sql "SELECT `user_ID`,`user_username`,`user_status` FROM `noobsonline_users` WHERE `user_lastaction` > $fivemin_ago_ts"
    (Backticks are on the key next to '1')

    HTH,
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I changed the sql function with the backticks and i got exactly the same results as before, they dont make a difference?

    It seems that with or without them there is something wrong with the way that something is selected from the database and/or the way that it is put into the database?

  • #4
    Regular Coder meth's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Is noobsonline_users.user_lastaction mysql format datetime?
    I do Web Design, Brisbane based.
    More time spent in PHP/MySQL Web Development.
    And Search Engine Optimisation takes up the rest of it.

  • #5
    New to the CF scene
    Join Date
    Dec 2006
    Location
    Chelmsford, Essex
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok i have just realiesd that i have made a foolish mistake, thats why its not working, i havnt extracted the right things (mis spellings of variables)

    really sorry for the hastle.

    Maybe while we are here we can debug another program that i have written.

    Its a custom news feed that i want to be able to clish a button saying next 10 articles and i only want it to show the link if there is more results. I have written the code below and dont know what to put in the bit that says "SOME TEST THAT THERE ARE MORE ITEMS AFTER THIS PAGE" so that it doesnt show the next link if there is no more results?

    PHP Code:
    <?php
    include("includes/header.inc");
    include(
    "includes/style.inc");
    if ( 
    $_GET[limit] == "" )
    {
        
    $newslimit1 "0";
    }
    else
    {
        
    $newslimit1 $_GET[limit];
    }

    $newslimit2 $newslimit1 10;

    echo
    "<span class='Lheading'>Welcome $_SESSION[login_username]</span><br /><br />
        Welcome to Noobs Online.co.uk<br /><br />
        <span class='Mheading'>Latest News</span><br /><br />"
    ;
    $news_sql "SELECT * FROM noobsonline_news ORDER BY news_ID DESC LIMIT $newslimit1, $newslimit2";
    $news_result mysql_query($news_sql);
    while (
    $news_row mysql_fetch_array($news_result))
    {
        
    extract($news_row);
        echo
    "<span class='XSheading'>$news_title</span><br />
        $news_text<br />
        <b>By:</b> $news_author <b>on</b> $news_date <b>at</b> $news_time<br /><br />"
    ;
        if(
    $counter == 0)
        {
            echo
    "";
        }
        
    $counter++;
    }

    $bottomlimit $newslimit1 10 ;
    $toplimit $newslimit2 ;

    echo
    "&nbsp;&nbsp;";

    if ( 
    $bottomlimit > -
    {
        echo
    "<a href='index.php?limit=$bottomlimit'>&lt;&lt; Last 10 &lt;&lt;</a>";

    else
    {
        echo 
    "&lt;&lt; Last 10 &lt;&lt;";
    }
    echo 
    " <b>::</b> ";
    if (
    SOME TEST THAT THERE ARE MORE ITEMS AFTER THIS PAGE)
    {
        echo
    "<a href='index.php?limit=$toplimit'>&gt;&gt; Next 10 &gt;&gt;</a>";

    else 
    {
        echo 
    "&gt;&gt; Next 10 &gt;&gt;";
    }
    include(
    "includes/footer.inc");
    ?>


  •  

    Posting Permissions

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