...

View Full Version : website users online script??



mxr156
12-23-2006, 11:14 PM
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



if ( $login_username_num == 1 )
{
$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 > 0 )
{
$_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
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")-5, date("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 == 0 )
{
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

whizard
12-23-2006, 11:51 PM
Be sure to surrond your field and table names in backticks, like this:



$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

mxr156
12-24-2006, 12:03 AM
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?

meth
12-24-2006, 01:15 AM
Is noobsonline_users.user_lastaction mysql format datetime?

mxr156
12-24-2006, 02:50 AM
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
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 > -9 )
{
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");
?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum