for some reaosn my code is displaying the page if its the last 1 they viewed or are viewing at any time at all.. how would i set it so its only showing those viewing the page in the last 15 minutes
PHP Code:
<?php $sql = "SELECT * FROM useronline
WHERE
file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=reply%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=mainforums%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=post%' AND
timestamp < 900";
$res = mysql_query($sql) or die('Error: '.mysql_error());
if(mysql_num_rows($res) > 0) {
echo '<div class="CurrentlyOnline">';
while($row = mysql_fetch_assoc($res))
echo $row['user'].'<br />';
echo '</div>';
}?>
900 seconds isn't enough, unless you're testing for something older than January 1, 1970 00:15.
You want you're check to be time() - 900:
PHP Code:
timestamp < " . time() - 900;
This will return any results that have occured more than 15 minutes ago. To reverse it, you'll want to do timestamp > " . time() - 900;. That will give you any results within the last 15 minutes.
You can also do this through pure SQL.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
$sql = "SELECT * FROM useronline
WHERE
file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=reply%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=mainforums%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=post%' AND
timestamp > ' . time() - 900 '";
$res = mysql_query($sql) or die('Error: '.mysql_error());
if(mysql_num_rows($res) > 0) {
echo '<div class="CurrentlyOnline">';
while($row = mysql_fetch_assoc($res))
echo $row['user'].'<br />';
echo '</div>';
}
ok i have done it but for some reason it displays even the people who have been on the page for 2 days ect (these are people who closed the browser on the page)
Change you're SQL precedence.
Logically, the only place the time is being compared on is in conjunction with file LIKE 'http://www.runningprofiles.com/members/index.php?page=post%'.
PHP Code:
$sql = "SELECT * FROM useronline
WHERE
(file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=reply%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=mainforums%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or
file LIKE 'http://www.runningprofiles.com/members/index.php?page=post%') AND
timestamp > " . time() - 900;
Or you can move the timestamp up to the first check since the and has priority. Either way, you'll need the brackets unless you replace with an IN clause.
Fixed you're quotations as well.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Because time() is a php function and not compatible with sql. You can do this with an sql command though, I believe its UNIX_TIMESTAMP() which returns an integer time.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Because time() is a php function and not compatible with sql. You can do this with an sql command though, I believe its UNIX_TIMESTAMP() which returns an integer time.
can use mysql function now(), in this case now() - 900 have same effect.
Edit:checked and I was wrong, now() don't return unix timestamp