Jump to content

Recommended Posts

  • Replies 94
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

$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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.