Jump to content

[SOLVED] show users online


alohatofu

Recommended Posts

  • Replies 94
  • Created
  • Last Reply

$time=time();
$timeout=time()+(60*60); #now+1hour
mysql_query("UPDATE `username` SET timestamp='$time' WHERE memberId='$id' LIMIT 1"); 
$query=mysql_query("SELECT * FROM `surv_member` WHERE `online`='1' AND `timestamp`>='$timeout'")
or die(mysql_error());
while($row=mysql_fetch_array($query)){
mysql_query("UPDATE `username` SET online='0' WHERE memberId='{$row['id']}' LIMIT 1"); 
$row['online'];
print "UPDATE `username` SET online='0' WHERE memberId='{$row['id']}' LIMIT 1";
}

//spit out the results
mysql_close();
print "{$row['username']}";

 

Still didnt' output anything.  On column online what type it should be? Binary?

Code revamp:

 

<?php

$time=time();

$timeout=time()+(60*60); #now+1hour
`
mysql_query("UPDATE `username` SET `timestamp` = '" . $time . "' WHERE `memberId` = '" . $id . "' LIMIT 1")
or die("Update Query 1: " . mysql_error()); 

$query = mysql_query("SELECT * FROM `surv_member` WHERE `online`= '1' AND `timestamp` >= '" . $timeout . '")
or die("SELECT Stament: " . mysql_error());

while($row=mysql_fetch_array($query)){
     mysql_query("UPDATE `username` SET `online` = '0' WHERE `memberId` = '" . $row['id'] . "' LIMIT 1")
or die("Update Query 2: " . mysql_error());

print $row['online'];
}

mysql_close();
?>

try this

 

on every page ($id = userid i assumed that is set)

<?php
$time=time();
$timeout=time()+(60*60); #now+1hour
mysql_query("UPDATE `username` SET timestamp='$timeout' WHERE memberId='$id' LIMIT 1");

$query=mysql_query("SELECT * FROM `surv_member` WHERE `timestamp` >= '$time'") or die(mysql_error());
while($row=mysql_fetch_array($query))
{
$display[] = $row['username'];
}

//spit out the results
mysql_close();
foreach($display as $d)
{
print "$d<br />";
}
?>

 

 

logout

<?php
$time=time();
mysql_query("UPDATE `username` SET timestamp='$time' WHERE memberId='$id' LIMIT 1");

?>

 

No online field or login script required

Code revamp:

 

<?php

$time=time();

$timeout=time()+(60*60); #now+1hour
`
mysql_query("UPDATE `username` SET `timestamp` = '" . $time . "' WHERE `memberId` = '" . $id . "' LIMIT 1")
or die("Update Query 1: " . mysql_error()); 

$query = mysql_query("SELECT * FROM `surv_member` WHERE `online`= '1' AND `timestamp` >= '" . $timeout . '")
or die("SELECT Stament: " . mysql_error());

while($row=mysql_fetch_array($query)){
     mysql_query("UPDATE `username` SET `online` = '0' WHERE `memberId` = '" . $row['id'] . "' LIMIT 1")
or die("Update Query 2: " . mysql_error());

print $row['online'];
}

mysql_close();
?>

 

there are syntax errors somewhere on here. I couldn't get it to accept

try this

 

on every page ($id = userid i assumed that is set)

<?php
$time=time();
$timeout=time()+(60*60); #now+1hour
mysql_query("UPDATE `username` SET timestamp='$timeout' WHERE memberId='$id' LIMIT 1");

$query=mysql_query("SELECT * FROM `surv_member` WHERE `timestamp` >= '$time'") or die(mysql_error());
while($row=mysql_fetch_array($query))
{
$display[] = $row['username'];
}

//spit out the results
mysql_close();
foreach($display as $d)
{
print "$d<br />";
}
?>

 

 

logout

<?php
$time=time();
mysql_query("UPDATE `username` SET timestamp='$time' WHERE memberId='$id' LIMIT 1");

?>

 

No online field or login script required

 

it doesn't like the foreach statement

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\sb\index.php on line 567

update

<?php
$time=time();
$timeout=time()+(60*60); #now+1hour
mysql_query("UPDATE `username` SET timestamp='$time' WHERE memberId='$id' LIMIT 1");

$query=mysql_query("SELECT * FROM `surv_member` WHERE `timestamp`>='$timeout'") or die(mysql_error());
$display = array();
while($row=mysql_fetch_array($query))
{
$display[] = $row['username'];
}

//spit out the results
mysql_close();
foreach($display as $d)
{
print "$d<br />";
}
?>

Shaun,

 

When i put your code I have

 

Parse error: syntax error, unexpected T_LNUMBER in C:\xampp\htdocs\sb\index.php on line 556

 

line 556 is

    mysql_query("UPDATE `username` SET `online` = '0' WHERE `memberId` = '" . $row['id'] . "' LIMIT 1")

 

lol

would help if i check the logic a little closer

 

<?php
echo "ID = $id"; //Added for debugging
$time=time();
$timeout=time()+(60*60); #now+1hour
mysql_query("UPDATE `surv_member` SET timestamp='$time' WHERE memberId='$id' LIMIT 1");

$query=mysql_query("SELECT * FROM `surv_member` WHERE `timestamp`>='$timeout'") or die(mysql_error());
$display = array();
while($row=mysql_fetch_array($query))
{
$display[] = $row['username'];
}

//spit out the results
mysql_close();
foreach($display as $d)
{
print "$d<br />";
}
?>

 

ok done

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.