yaytome Posted October 27, 2007 Share Posted October 27, 2007 Hi to everyone, i'm new here and i'm looking for a good tutorial about paging and a good tutorial on showing how many guests and how many logged members there are actually.. Just like this forum Can someone tell me where to find it? [especially the tutorial on showing how many guests and how many logged members there are] Any help would be appreciated. Thanks a ton Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/ Share on other sites More sharing options...
yaytome Posted October 27, 2007 Author Share Posted October 27, 2007 Oh No one :'( Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379504 Share on other sites More sharing options...
PHP_PhREEEk Posted October 27, 2007 Share Posted October 27, 2007 You waited 10 mins before acting like you're being ignored? Try the Freelance board when time is of the essence. PhREEEk Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379529 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 I don't want someone to write it for me. just a good tutorial to get me off the ground.. I got the paging the phpfreaks.. but to find a tutorial that will allow me to show users and members is hard to find. Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379552 Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 paging? showing certain data? that is irrelavent. Pagination is what I am assuming you are talking about and it is not dependent on the fields you are taking out of sql, only the criteria of the search. Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379561 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 paging? showing certain data? that is irrelavent. Pagination is what I am assuming you are talking about and it is not dependent on the fields you are taking out of sql, only the criteria of the search. Huhh yeah pagination.. i got this one working.. but now im only searching tips to make this who is online script to show the number of visitors and members.. can someone tell me how to begin with this? Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379568 Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 try http://www.google.com Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379569 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 I tried man but something is bothering me.. Most of the tutorial i've seen add a visitor though his ip, which is correct i presume? now my question is, when this visitor logs in, he should be removed from the visitors list, right? but wouldn't the script read his ip and insert him once again in the visitors list?? Sorry if i'm asking those question. I just started with php and mysql and well, there are lots of genius in php in this forum, i might get some ideas.. Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379578 Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 because once they are logged in it says if($_SESSION['loggedin'] == "yes"){ //ignore all the visitor pool and verify they are part of the user pool } Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379587 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 I have a code which shows how many visitors are viewing the website.. can you help me with the next block? I mean, show the numbers of logged members? Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379597 Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 well I need to see what you have to even have a clue what you are doing, and you will have to understand what you have to make it work. Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379598 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 Ok, i have two tables #active_guests# ip | timestamp and table #active_users# username | timestamp Here is the code i have to show the number of active users <?php session_start(); $conn = mysql_connect(".....","....","...."); mysql_select_db("tech"); $time = time(); $time_out = 300; $guest_time_out = time()-300; $member = $_SESSION['member']; $ip = $_SERVER['REMOTE_ADDR']; $sql = "SELECT * FROM active_guests WHERE ip = '$ip'"; $result = @mysql_query($sql,$conn); $num = @mysql_num_rows($result); if($num == 0){ $q = "INSERT INTO active_guests(ip,timestamp)VALUES('$ip','$time')"; $res = @mysql_query($q); }else{ $q = "UPDATE active_guests SET timestamp = '$time' WHERE ip = '$ip'"; $res = @mysql_query($q); } $cnx = "SELECT * FROM active_guests"; $resultat = @mysql_query($cnx); $visitors = @mysql_num_rows($resultat); // if over 5 minute, delete session $sql4="DELETE FROM active_guests WHERE time<$guest_time_out"; $result4=@mysql_query($sql4); echo "Visitors online : $visitors "; ?> as you can see, ##$member = $_SESSION['member']; is when someone logs in.. Now if someone logs in, it should add them to the active_users table and remove them from the visitors list.. the problem is that i don't know how to get it to work.. Hope i'm not bugging you with this. Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379609 Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 well copy that table of guest users online, for logged in users then say <?php if(!empty($message)){ //delete from the guest table where ip = the users ip //Insert into or update member online table } //Check guest and users online for old timestamps and delete where needed. ?> That is the just idea, use what you got and it should make sense after you make the new table/ add in this tidbit. Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379612 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 if(!empty($message)) what is $message refering to? I don't get this part Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379618 Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 $member, sorry thought it said $message which didn't make sense to me Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379620 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 ok thats what im using now, but it doesn't seems to work right <?php session_start(); include('configuration.php'); include('sessions.php'); $conn = mysql_connect($server,$dbname,$password); mysql_select_db($dbname); $time = time(); $time_out = 300; $guest_time_out = time()-300; $member = $_SESSION['member']; $ip = $_SERVER['REMOTE_ADDR']; $sql = "SELECT * FROM active_guests WHERE ip = '$ip'"; $result = @mysql_query($sql,$conn); $num = @mysql_num_rows($result); if($num == 0){ $q = "INSERT INTO active_guests(ip,timestamp)VALUES('$ip','$time')"; $res = @mysql_query($q); }else{ $q = "UPDATE active_guests SET timestamp = '$time' WHERE ip = '$ip'"; $res = @mysql_query($q); } // grab result for visitors $cnx = "SELECT * FROM active_guests"; $resultat = @mysql_query($cnx); $visitors = @mysql_num_rows($resultat); // if over 5 minute, delete session $sql4="DELETE FROM active_guests WHERE time<$guest_time_out"; $result4=@mysql_query($sql4); echo "Visitors : $visitors "; if(!empty($member)){ //delete the ip of the member in the active guest table $del = "DELETE FROM active_guests WHERE ip = '$ip'"; $delresult = @mysql_query($del); //Insert into or update member online table $sql = "SELECT * FROM active_users WHERE username = '$member'"; $result = @mysql_query($sql); $num = @mysql_num_rows($result); if($num == 0) { $sql = "INSERT INTO active_users(username,timestamp)VALUES('$member','$time')"; $result = @mysql_query($sql); }else{ $sql = "UPDATE active_users SET timestamp = '$time' WHERE username = '$member'"; $result = @mysql_query($sql); } } $grab = "SELECT * FROM active_users"; $result = @mysql_query($grab); $count = mysql_num_rows($result); echo "<br>Members online : $count "; ?> When im logged in, it doesn't seem to delete my IP from the active_guest table, but Members online get to 1, and when i logged out, members is still on 1 Why is it so? Did i implement the code well? Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379635 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 The only problem is when i logout, it wont remove me from the active_users table.. I wonder how i can get this to work :S Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379643 Share on other sites More sharing options...
cooldude832 Posted October 28, 2007 Share Posted October 28, 2007 well first off don't suppress errors with that @ sign, its never good to do so ever even on a live site. (unless its like corporate level stuff). Secondly stuff using that * operator its going to lag up your pages, just say select count(*) and then say $result = mysql_query($sql) or die(Mysql_error()); if(mysql_result($result,0)>0){ it will save you a lot if you replace all of your queries. Now for the actual issues. You don't have a delete query set (unless its part of your logout script which you aren't displaying to us). so this is why member count stays up. as for the guest count you can't delete something you are creating on your pages since you are making that query on the same page use some logic. I cleaned up your stuff cause It was well ugly to me, its still not perfect, but it should be more coherent. Also Its untested so it will probably error <?php session_start(); include('configuration.php'); include('sessions.php'); $conn = mysql_connect($server,$dbname,$password); mysql_select_db($dbname); $time = time(); $time_out = 300; $guest_time_out = time()-300; $member = $_SESSION['member']; $ip = $_SERVER['REMOTE_ADDR']; if(!empty($member)){ //delete the ip of the member in the active guest table $del = "DELETE FROM active_guests WHERE ip = '$ip'"; $delresult = mysql_query($del) or die(mysql_error()); //Insert into or update member online table $sql = "SELECT count(*) FROM active_users WHERE username = '$member'"; $result = mysql_query($sql) or die(mysql_error()); $num = mysql_num_rows($result); if($num == 0){ $sql = "INSERT INTO active_users(username,timestamp)VALUES('$member','$time')"; $result = mysql_query($sql) or die(mysql_error()); } else{ $sql = "UPDATE active_users SET timestamp = '$time' WHERE username = '$member'"; $result = mysql_query($sql) or die(mysql_error()); } } else{ $sql = "SELECT count(*) FROM active_guests WHERE ip = '$ip'"; $result = mysql_query($sql,$conn)or die(mysql_error()); if(mysql_results($result,0) == 0){ $q = "INSERT INTO active_guests(ip,timestamp)VALUES('$ip','$time')"; $res = mysql_query($q) or die(mysql_error()); } else{ $q = "UPDATE active_guests SET timestamp = '$time' WHERE ip = '$ip'"; $res = mysql_query($q) or die(mysql_error()); } } // if over 5 minute, delete session $sql4="DELETE FROM active_guests WHERE time<$guest_time_out"; $result4 = mysql_query($sql4); // if over 5 minute, delete session $sql5 = "DELETE FROM active_users WHERE time<$guest_time_out"; $result5 = mysql_query($sql5) or die(mysql_error()); // grab result for visitors $cnx = "SELECT count(*) FROM active_guests"; $resultat = mysql_query($cnx) or die(mysql_error()); $visitiors = mysql_result($resultat,0); $grab = "SELECT count(*) FROM active_users"; $result = mysql_query($grab) or die(mysql_error()); $count = mysql_num_rows($result); echo "Visitors : $visitors "; echo "<br />Members online : $count "; ?> to your logout script add <?php $q = "Delete from `active_users` Where Username = '".$_SESSION['member']."'"; $r = mysql_query($q) or die(mysql_error()); ?> and that should help EDIT: I noticed a couple of minor errors so do a recopy if u are reusing it Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379647 Share on other sites More sharing options...
yaytome Posted October 28, 2007 Author Share Posted October 28, 2007 well first off don't suppress errors with that @ sign, its never good to do so ever even on a live site. (unless its like corporate level stuff). Secondly stuff using that * operator its going to lag up your pages, just say select count(*) and then say $result = mysql_query($sql) or die(Mysql_error()); if(mysql_result($result,0)>0){ it will save you a lot if you replace all of your queries. Thats what i needed to know Thanks for the tip tho. I appreciate ur time.. your script and running just fine..just modify it a bit to suits my need.. it did what i wanted to .. Thanks for your help. I should save this example somewhere just to learn from it.. I cleaned up your stuff cause It was well ugly to me, Don't forget that i'm new to php .. Cheers and thanks again Quote Link to comment https://forums.phpfreaks.com/topic/75047-solved-can-someone-guide-me/#findComment-379655 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.