Kingy Posted February 9, 2008 Share Posted February 9, 2008 i have a users online script, that will insert a users ip and a 3 minute timestamp. obviously if they arn't there in 3 minutes that user is now offline. it works fine, but what i am going to do now is also insert the $_SESSION[username] to tell if the user is a member or not. i no how to insert it and what not but how do i make it so its like: Users online: 12 Members online: 5 for the users online i have $usersonline = mysql_query("SELECT DISTINCT ip FROM usersonline") or die(mysql_query()); but how do i get it so it selects the rows that have a username in them? Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/ Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 amend your users online table to include a bool field of Registered/not Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462834 Share on other sites More sharing options...
Kingy Posted February 9, 2008 Author Share Posted February 9, 2008 so do something like if(isset($_SESSION[username])) { insert into users online (timestamp, ip, registered) values (..., ....., 1) } else { insert into users online (timestamp, ip, registered) values (..., ....., 0) } and then just select all rows where registered = 1 ? Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462842 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 Well I think you might be able to get away with this <?php $q = "Insert into `user_online` (timestamp,ip,registered) values('','',$_SESSION['UserID'])"; ?> If registered is a Bool and the value of $_SESSION['UserID'] is not null or 0 then the user will be "True" and it should insert a 1 not a 0 and if you default it to 0 and you insert $_SESSION['UserID'] it will insert '' when it is undefined and result in it going to a default value of 0. So do it like I gave and make registered be a Bool field default 0 Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462844 Share on other sites More sharing options...
Kingy Posted February 9, 2008 Author Share Posted February 9, 2008 Warning: Wrong parameter count for mysql_query() on line 24 $registered = isset($_SESSION['username']) ? $_SESSION['username'] : ''; $usersonlineinsert = mysql_query("INSERT INTO usersonline (timestamp, ip, registered) VALUES ('$timestamp','$ip', '$registered')") or die(mysql_query()); Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462857 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 your or die should be mysql_error Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462859 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 use $q = "INSERT INTO `usersonline` (timestamp, ip, regsitered) VALUES('".$timestamp."', '".$ip."', '".$_SESSION['username']."')"; $useronlineinsert = mysql_query($q) or die(Mysql_error()."<Br /><br />".$q); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462864 Share on other sites More sharing options...
Kingy Posted February 9, 2008 Author Share Posted February 9, 2008 cooldude it doesn't work, it is saying incorrect integer value. eg my nickname Kingy is not a integer, therefore it can't be placed into the field Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462875 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 yeah wasn't sure if it take it so try <?php if(isset($_SESSION['username'])){$register = 1;} $q = "INSERT INTO `usersonline` (timestamp, ip, regsitered) VALUES('".$timestamp."', '".$ip."', '".$register."')"; $useronlineinsert = mysql_query($q) or die(Mysql_error()."<Br /><br />".$q); ?> Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462880 Share on other sites More sharing options...
Kingy Posted February 9, 2008 Author Share Posted February 9, 2008 ok yeah cool, works now. thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462882 Share on other sites More sharing options...
cooldude832 Posted February 9, 2008 Share Posted February 9, 2008 check that solved button Quote Link to comment https://forums.phpfreaks.com/topic/90273-users-online/#findComment-462883 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.