Jump to content

Recommended Posts

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

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.

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

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)

 

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?

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=%'

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>';
}
}?> 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.