Jump to content


[SOLVED] Help with online users list


2 replies to this topic

#1 Mr. Jay

    Young Padawan

  • Members
  • Pip
  • 81 posts

Posted 23 July 2007 - 07:22 AM

I am trying to get it to output like this
Example 1: (1 person)
User7
Example 2: (2 users)
User1, User7
Example 3: (3 users)
User1, User2, User7
Example 4: (No users)
No Users Online

This is what I got so far
<?php
	$conn = mysql_connect("localhost","mylogin","mypass");
	$db = mysql_select_db("test");
	$users_query = mysql_query("SELECT * FROM test_users ORDER BY lastactivity");
	$users_count = mysql_num_rows($user_query);
	if ($users_count > 1)
	{
		while($row = mysql_fetch_array($user_query))
		{
			if ($row['lastactivity'] > time())
			{
				echo $row['username'].", ";
			}
		}
	}
	else
	{
		echo "No Users Online";
	}
	mysql_close($conn);
?>

Edited by Mr. Jay, 23 July 2007 - 01:31 PM.


#2 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 23 July 2007 - 11:30 AM

Implode works wonders, lol. :biggrin:

<?php
	$conn = mysql_connect("localhost","mylogin","mypass");
	$db = mysql_select_db("test");
	$users_query = mysql_query("SELECT * FROM test_users ORDER BY lastactivity");
	$users_count = mysql_num_rows($user_query);
	if($users_count > 0){
		while($row = mysql_fetch_array($user_query)){
			$users_online[] = $row['username'];
		}
		echo implode(', ', $users_online);
	}
	else{
		echo "No Users Online";
	}
	mysql_close($conn);
?>

I don't really get how the 'lastactivity' column could possibly be greater than the call to time(), since that would mean the last thing they did was in the future. :D

#3 Mr. Jay

    Young Padawan

  • Members
  • Pip
  • 81 posts

Posted 23 July 2007 - 01:00 PM

Thanks it worked perfect :biggrin:

The 'lastactivity' column is used for 5mins time after they clicked "time()*(60*5)", that way it don't show any unactive users :D





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users