runnerjp Posted October 24, 2008 Share Posted October 24, 2008 throughout my site i track users... i have a forum section and want to display how many users and who is viewing the forum... the thing is i store the page next to the username that they are on and im woundering if i could search for short hand of the url... examples will help make this clearer... here are a few examples of links on my forum index.php?page=post&forum=<?php echo $forum?> index.php?page=mainforums index.php?page=reply&id=<? echo $id ?> and so on... as you guys can see there are alot of veriations... is there away to search for the links that contain index.php?page=reply index.php?page=mainforums index.php?page=post to just display them?? Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/ Share on other sites More sharing options...
JonnoTheDev Posted October 24, 2008 Share Posted October 24, 2008 Store the cut version also or break it up to make it searchable. Would be easier if you used friendly rewritten urls Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-673769 Share on other sites More sharing options...
.josh Posted October 24, 2008 Share Posted October 24, 2008 Why not make a column in your user's table called currentlyAt or something and whenever a user loads a page, it takes the $_GET['page'] var and puts that value in their row and then base your query to show where users are, off currentlyAt? Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-673795 Share on other sites More sharing options...
runnerjp Posted October 24, 2008 Author Share Posted October 24, 2008 you would i be able to cut down the url with $_GET['page'] just to show page=post Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-673866 Share on other sites More sharing options...
.josh Posted October 24, 2008 Share Posted October 24, 2008 ermm...either you misunderstand me or else I misunderstand you. Okay for example, if I were to click on the following link: http://www.somesite.com/index.php?page=blah Inside index.php I could then do this: echo $_GET['page']; and it would echo 'blah'. Variables passed through the url are accessed through the $_GET array. You are already making use of the $_GET array in your script, based on what you said in your OP. So I don't really understand why I'm explaining this to you...unless that isn't your script and you're tryin' to mess around with it. Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-673881 Share on other sites More sharing options...
runnerjp Posted October 24, 2008 Author Share Posted October 24, 2008 sorry i misunderstood yo, read it wrong... i thought u was advising me not to use the get method lol Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-673952 Share on other sites More sharing options...
runnerjp Posted October 24, 2008 Author Share Posted October 24, 2008 ok i have gone this way about it $sql = "SELECT * FROM useronline WHERE file LIKE WHERE file LIKE 'http://www.runningprofiles.com/members/index.php?page=reply%' OR file LIKE 'http://www.runningprofiles/members/index.php?page=mainforums%' OR file LIKE 'http://www.runningprofiles/members/index.php?page=post%' AND timestamp > now() - interval 10 minute"; $res = mysql_query($sql) or die('Error: '.mysql_error()); if(mysql_num_rows($res) > 0) { echo '<div class="CurrentlyOnline">'; while($row = mysql_fetch_assoc($res)) echo $row['user'].'<br />'; echo '</div>'; } ?> but im getting the error Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE file LIKE 'http://www.runningprofiles.com/members/index.php?page=reply%' at line 2 Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674040 Share on other sites More sharing options...
.josh Posted October 24, 2008 Share Posted October 24, 2008 WHERE file LIKE WHERE to WHERE Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674047 Share on other sites More sharing options...
runnerjp Posted October 24, 2008 Author Share Posted October 24, 2008 ahh yes doh lol getting late! for some reaosn its only recording users on file LIKE 'http://www.runningprofiles.com/members/index.php?page=reply%' OR and nothing else? Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674065 Share on other sites More sharing options...
.josh Posted October 24, 2008 Share Posted October 24, 2008 That's because you forgot the .com on the other urls. Also, are you wanting to record only those 3 pages, or any page= ? Or anywhere on your site? because depending on the answer to those questions, you can reduce that down to one LIKE or even take them all out and just use the last condition (the timestamp) Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674102 Share on other sites More sharing options...
runnerjp Posted October 25, 2008 Author Share Posted October 25, 2008 only on those 3 pages Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674236 Share on other sites More sharing options...
.josh Posted October 25, 2008 Share Posted October 25, 2008 Okay well then it's because you forgot the .com on the other two. Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674302 Share on other sites More sharing options...
runnerjp Posted October 26, 2008 Author Share Posted October 26, 2008 ok with my given code... <?php $sql = "SELECT * FROM useronline WHERE file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=reply%' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=mainforums%' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=post%' AND timestamp == now()"; $res = mysql_query($sql) or die('Error: '.mysql_error()); if(mysql_num_rows($res) > 0) { echo '<div class="CurrentlyOnline">'; while($row = mysql_fetch_assoc($res)) echo $row['user'].'<br />'; echo '</div>'; }?> i get You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '== now()' at line 8 as im trying to show the users on the page right now? Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674969 Share on other sites More sharing options...
.josh Posted October 26, 2008 Share Posted October 26, 2008 That's because in sql you use = not == for comparison. And also, dude, you said you only wanted those 3 pages but in your script you have even more! If you are wanting to return all index.php?page=xxxx's at the very least, it would be better to have one LIKE that does this: 'http://www.runningprofiles.com/members/index.php?page=%' Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674972 Share on other sites More sharing options...
runnerjp Posted October 26, 2008 Author Share Posted October 26, 2008 sorry i had message 2wise lol... im just lookign for the forum areas.. for some reaosn its not showing the users that are right now but even those that accessed the page 2 days ago? Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674974 Share on other sites More sharing options...
runnerjp Posted October 26, 2008 Author Share Posted October 26, 2008 i have edit it a little but its not shown anyone now <?php $sql = "SELECT * FROM useronline WHERE file LIKE 'http://www.runningprofiles.com/members/index.php?page=message%' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=reply%' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=mainforums%' or file LIKE 'http://www.runningprofiles.com/members/index.php?page=post%'"; $res = mysql_query($sql) or die('Error: '.mysql_error()); if(mysql_num_rows($res) > 0) { echo '<div class="CurrentlyOnline">'; while($row = mysql_fetch_assoc($res)) $last_active = time() - $row['timestamp']; if ($last_active < 300 ){ echo $row['user'].'<br />'; echo '</div>'; } }?> Link to comment https://forums.phpfreaks.com/topic/129960-getting-users-on-a-page/#findComment-674984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.