reportingsjr Posted August 4, 2006 Share Posted August 4, 2006 I know how to create a list that says "7 guests online" and such and it goes up everytime someone visits, but how do you make it go back down when someone leaves? I realize you can make a logout page or a leave site page but in my case people will always be just hitting the close button or going to another website. How can I make it go up and down according to how many people are at your website? I know of a site that does this (uiv2.com, scroll to the bottom and there will be a lin k that says X users online, click it and you will see a list) but I cant figure out how to do it...I really want to know how this is done!! Link to comment Share on other sites More sharing options...
aspnetguy Posted August 4, 2006 Share Posted August 4, 2006 try this...Google is your friend http://www.tutorialized.com/forum/viewtopic.php?t=46 Link to comment Share on other sites More sharing options...
reportingsjr Posted August 4, 2006 Author Share Posted August 4, 2006 True, I shoulda googled it. Ill check that out aspnetguy. Thank you!EDIT: read it.. Wow, shoulda realized how simple it is lol. Kinda what I wanted, but it only shows users that have gone to the page/refreshed it in the past 5 minutes. Thats okay I guess.. Thank you! Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 4, 2006 Share Posted August 4, 2006 And your enemy, if you don't know what you're looking for, lol :)It has got something to do with session endings, hasn't it? Link to comment Share on other sites More sharing options...
ThePsion5 Posted August 4, 2006 Share Posted August 4, 2006 *Quietly yanks script* :) Link to comment Share on other sites More sharing options...
reportingsjr Posted August 4, 2006 Author Share Posted August 4, 2006 Ah no, check out my site (link in siggy) and scroll to the bottom.What it is, is that you insert the ip and time that the site was viewed at,then you do a select query for any time that was in the past X minutes. Heres my code for my counter and visit thing now: $query= "DELETE FROM `counter` WHERE `ip` = '{$_SERVER['REMOTE_ADDR']}'";$result=mysql_query($query);$time = time();$query= "INSERT INTO `counter` VALUES ('NULL', '{$_SERVER['REMOTE_ADDR']}', '{$time}')";$result= mysql_query($query);$query= "SELECT * FROM `counter` ORDER BY `number` DESC LIMIT 1";$result = mysql_query($query);$row = mysql_fetch_object($result);echo "This page has been viewed {$row->number} times.<br />";$maxtime = time() - (60 * 10); $query = "SELECT * FROM `counter` WHERE `timeviewed` >= $maxtime";$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());$num = "0";if(mysql_num_rows($result) > 0){while($row = mysql_fetch_row($result)){ $num++;}}else{echo "No one on this site currently!";}if($num >= "2"){echo "{$num} people are online or have visited the site in the past 10 minutes.";}else{echo "{$num} person is online or has visited the site in the past 10 minutes.";} Now if you go to my site and scroll to the bottom you will see what it says :)Thanks aspnetguy!! Link to comment Share on other sites More sharing options...
ThePsion5 Posted August 4, 2006 Share Posted August 4, 2006 A minor optimization to your code - instead of: $query = "SELECT * FROM `counter` WHERE `timeviewed` >= $maxtime";$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());$num = "0";if(mysql_num_rows($result) > 0){while($row = mysql_fetch_row($result)){$num++;} You could have this instead: $query = "SELECT COUNT(*) FROM `counter` WHERE `timeviewed` >= $maxtime";$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());$resultArray = mysql_fetch_array($result);$num = $resultArray[0];} It won't matter much as long as the database and server are on the same computer, but it could save you alot of network traffic otherwise. Link to comment Share on other sites More sharing options...
reportingsjr Posted August 4, 2006 Author Share Posted August 4, 2006 Eh its alright. Someone voted they didnt like my new site design they should have seen it before.. then they would say they like it Link to comment Share on other sites More sharing options...
Little Goat Posted August 4, 2006 Share Posted August 4, 2006 um, you really need to do something about your site...the first time it said something about a login, then a fewimages and a little more text, the second time, there was just a little text, and the third time, just the background. Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted August 4, 2006 Share Posted August 4, 2006 ...reportingsjr, you should use ajax to update your chat box, not JS!!!ajax works by talking to the server though js, but it doesn't refresh the page to update content... unlike the js comand to refresh the page, which fereshes the page...it's really annoying. Link to comment Share on other sites More sharing options...
SFB Posted August 5, 2006 Share Posted August 5, 2006 ...reportingsjr, you should use ajax to update your chat box, not JS!!!ajax works by talking to the server though js, but it doesn't refresh the page to update content... unlike the js comand to refresh the page, which fereshes the page...it's really annoying.hey dan do you have ajax on your server? Link to comment Share on other sites More sharing options...
Jack McKalling Posted August 5, 2006 Share Posted August 5, 2006 I don't have a server at all Erm, you were talking to another Dan, mm sorry Link to comment Share on other sites More sharing options...
justsomeguy Posted August 5, 2006 Share Posted August 5, 2006 Ajax is not "on a server". Ajax is several technologies that you use together for a certain purpose. Specifically, you use javascript, XML (the J and the X in Ajax), and the document object model to send/receive requests without loading the page. It doesn't require the server to support anything unusual, but it does depend on the browser's document object model. Link to comment Share on other sites More sharing options...
reportingsjr Posted August 6, 2006 Author Share Posted August 6, 2006 you kidding me.. If you would look at the script right above where the chat is you would see this:<scipt href="includes/ajax.js" language="javascript"></script>Lol, maybe that will hit you. little goat, what exactly do you mean? Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted August 6, 2006 Share Posted August 6, 2006 O, well it didn't look like AJAX because it kept reloading the textarea and moving the scroller to the top... you should have it go back to the loacation it was at before the reloading of data. Link to comment Share on other sites More sharing options...
reportingsjr Posted August 6, 2006 Author Share Posted August 6, 2006 Yea, it just randomly started doing that. I even gave it to another website to try out (it improved the chat) and theres works that way.. Its odd. Link to comment Share on other sites More sharing options...
Little Goat Posted August 7, 2006 Share Posted August 7, 2006 well, I'm in opera, and all your webpage shows for me is the background.the source looks fine, but it won't show anything. maybe it's just me. it might have something to do with your comments; in a few spots you have one dash (-) instead of two, such as at the end of a few comments.I actually don't know...EDIT: it also might have to do with the fact that some of the attributes in the html tags are escaped (ex. \' ). Link to comment Share on other sites More sharing options...
reportingsjr Posted August 9, 2006 Author Share Posted August 9, 2006 Yea littlegoat, it doesnt work in IE either, says some stupid error like doucment.getElementById is null or not an object.. but I cant fix it from where im at . Link to comment Share on other sites More sharing options...
justsomeguy Posted August 9, 2006 Share Posted August 9, 2006 You can see javascript errors in Opera by going to Tools -> Advanced -> Error Console. From one of the dropdowns you can choose to only show Javascript errors. They are very informative, even give you the line and position where the error happened. If you have the web developer toolbar, there are 2 additional javascript shells under the Utils menu. Link to comment Share on other sites More sharing options...
reportingsjr Posted August 10, 2006 Author Share Posted August 10, 2006 I know both of those. Web dev. is one of the best toolbars ever . Ill fix that thing later.. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now