MadTechie Posted April 24, 2007 Share Posted April 24, 2007 change UPDATE `username` SET online='0' WHERE memberId='$row[id]' LIMIT 1 to UPDATE `username` SET online='0' WHERE memberId='{$row['id']}' LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237429 Share on other sites More sharing options...
alohatofu Posted April 24, 2007 Author Share Posted April 24, 2007 $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? Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237433 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 varchar(1) is easiest Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237434 Share on other sites More sharing options...
alohatofu Posted April 24, 2007 Author Share Posted April 24, 2007 bleh.. that shouldn't matter though right? I changed it and it didn't change anything. I guess it's on the UPDATE Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237441 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237446 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 What does it return? Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237451 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237453 Share on other sites More sharing options...
alohatofu Posted April 24, 2007 Author Share Posted April 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237454 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 what line? print that line... Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237456 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 ` on the 6th line Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237457 Share on other sites More sharing options...
alohatofu Posted April 24, 2007 Author Share Posted April 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237466 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 what error message does my script return? Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237469 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 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 />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237471 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 Dude, we are swamping the kid with code, alohat, try my code, then post back th me the error message you are receiving, then do the same with madtechcie's code Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237473 Share on other sites More sharing options...
alohatofu Posted April 24, 2007 Author Share Posted April 24, 2007 what error message does my script return? that syntax on the 6th line and there's something else on the script I'm still trying to figure out where is the syntax error =( Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237474 Share on other sites More sharing options...
alohatofu Posted April 24, 2007 Author Share Posted April 24, 2007 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") Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237483 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 missing ; EDIT: hate to ask but did my code work ? Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237485 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 no, or die is on the next line Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237488 Share on other sites More sharing options...
alohatofu Posted April 24, 2007 Author Share Posted April 24, 2007 Madtech, it didnt' give any error but it's not showing anything neither. Shaun, I'm still can't figure out where the syntax error is.. yes it's not missning the ; because "die" is on the next line Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237492 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 try commenting out the second update statement and the or die beneath it, do you still get an error? Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237495 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237498 Share on other sites More sharing options...
alohatofu Posted April 24, 2007 Author Share Posted April 24, 2007 commenting it still didn't take out the error here's the image Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237500 Share on other sites More sharing options...
MadTechie Posted April 24, 2007 Share Posted April 24, 2007 line 552 is missing a ) Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237502 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 do you have <?php $server = "localhost"; // usually localhost $db_user = "username"; $db_pass = "password"; $database = "survtask"; mysql_connect($server, $db_user, $db_pass); ?> above it? Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237503 Share on other sites More sharing options...
shaunrigby Posted April 24, 2007 Share Posted April 24, 2007 it goes off the page Quote Link to comment https://forums.phpfreaks.com/topic/48444-solved-show-users-online/page/2/#findComment-237504 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.