Jump to content
MakeWebGames

Users Online


The Coder

Recommended Posts

Hey,

After playing around with my Users Online, I can't seem to get it right. What I'm trying to achieve is, have a color code for each staff rank & Donators:

Admins = Gold

Secretaries = Blue

Assistants = Purple

Donators = Red

Any help would be deeply appreciated. :)

Here is my code:

 

<?php

require "globals.php";

if ($_GET['time'])
{
 $time=$_GET['time'];
}
else
{
 $time=15;
}
$cn=0;
$lk=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-1440*60");
$aa=mysql_num_rows($lk);
$ll=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-60*60");
$ab=mysql_num_rows($ll);
$lm=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-45*60");
$ac=mysql_num_rows($lm);
$ln=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-30*60");
$ad=mysql_num_rows($ln);
$lo=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-15*60");
$ae=mysql_num_rows($lo);
$he=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-1*60");
$hu=mysql_num_rows($he);
$q=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-{$time}*60 ORDER BY laston DESC");
?>
<table width=30% cellpading='1' cellspacing='0' border=0 align=left>
 <tr>
   <td>
     <b>Time Selector</b>
      </td></tr>
     <td>
     <a href='usersonline.php?time=1'>(1 Min)</a><br />
     <a href='usersonline.php?time=15'>(15 Mins)</a><br />
     <a href='usersonline.php?time=30'>(30 Mins)</a><br />
     <a href='usersonline.php?time=45'>(45 Mins)</a><br />
     <a href='usersonline.php?time=60'">(60 Mins)</a><br />
     <a href='usersonline.php?time=1440'>(24 Hours)</a><br />  
   </td>
   </tr>

<br /><br /><table width=50% cellpading='1' cellspacing='0' border=0 align=left>
   <tr>
      <td class=table>
           <h3></h3>

       <td class=table>
           <b>Gang</b>
       </td>
       <td class=table>
           <b><center>User</center></b>
       </td>
       <td>

       <td class=table>
           <b>Time Online</b>
       </td>
       <td class=table>
           <b>Action</b>
       </td>
   </tr>
<?php
           while($r=mysql_fetch_assoc($q))
           {
             $la=time()-$r['laston'];
             $unit="secs";
             if($la >= 60)
             {
               $la=(int) ($la/60);
               $unit="mins";
             }
             if($la >= 60)
             {
               $la=(int) ($la/60);
               $unit="hours";
               if($la >= 24)
               {
                 $la=(int) ($la/24);
                 $unit="days";
               }
             }
             $cn++;
$name=$r['username'];
$gangtag=$r['yourgangPREF'];

if($r['donatordays'] > 0)
{
$donator="<img src='donator.gif' width='9%' height='9%' alt='Donator: {$r['donatordays']} Days Left' title='Donator: {$r['donatordays']} Days Left' />";
} 
if($r['donatordays'] == 0)
{
$donator="";
}
if($r['user_level']== 2)
{
$staff="<img src= 'staff.gif' width='8%' height='8%' alt='Game Staff' title='Staff' />";
}
if($r['user_level']== 1)
{
$staff="";
}
if($r['userid']==1)
{
$owner="";
}

$r['username']="<a href='viewuser.php?u={$r['userid']}'><font color='{$r['colour']}'> $name   $owner $donator $staff</a>";

             print "<tr>
                      <td class=table>
                        $cn.
                      </td>
                      <td class=table >";
                      if ($r['gang'] > 0) {
                      print"
                        <a href='gangs.php?action=view&ID={$r['gang']}'><small>[View]</small></a>
                      </td>";
                      }
                      else {
                       print"
                        <small>No Gang</small>
                      </td>";
                      }
                      print"
                      <td class=table>
                        {$r['username']}
                      </td>
                      <td class=table>
                      ($la $unit) 
                      </td>
                      <td class=table>";
             $lb=time()-$r['last_login'];
             $units="secs";
             if($lb >= 60)
             {
               $lb=(int) ($lb/60);
               $units="mins";
             }
             if($lb >= 60)
             {
               $lb=(int) ($lb/60);
               $units="hours";
               if($lb >= 24)
               {
                 $lb=(int) ($lb/24);
                 $units="days";
               }
             }
             if($r['laston'] <= time()-15*15)
             {
               $lb="offline";
               $unit="";
             }
              print "{$lb} {$units}</td>";
             if($r['hospital'] > 0) {
             print"<td><small>Hospital</small></td>";
             }
              if($r['jail'] > 0) {
             print"<td><small>Jail</small></td>";
             }
              if($r['hospital'] == 0 AND $r['jail'] == 0) {
             print"<td><small>[<a href='attack.php?uid={$r['userid']}'>Attack</a>]</td>";
             }
             print"</tr>";
      } 

?>
   </td>
 </tr>
</table>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><table width=30% class='colortd' cellpading='1' cellspacing='0' border=0 align=left>
   <tr>
   <td class=table>
     <b>Statistics</b><br />
     Users online in the last minute: <?php print"{$hu}<br />"; ?>
     Users online in the last 15 minutes: <?php print"{$ae}<br />"; ?>
     Users online in the last 30 minutes: <?php print"{$ad}<br />"; ?>
     Users online in the last 45 minutes: <?php print"{$ac}<br />"; ?>
     Users online in the last hour: <?php print"{$ab}<br />"; ?>
     Users online in the last 24 hours: <?php print"{$aa}<br />"; ?>
   </td>
 <tr>
</table>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><table width=30% class='colortd' cellpading='1' cellspacing='0' border=0 align=left>
   <tr>
   <td class=table>
     <b>Legend</b><br />
     Admins = <font color=gold>Gold</font><br />
     Secretaries = <font color=blue>Blue</font> <br />
     Assistants = <font color=purple>Purple</font><br />
     Members = <font color=silver>Silver</font><br />
     Staff = <img src='staff.gif'></img><br />
     Donators = <img src='donator.gif'></img><br />
   </td>
 <tr>
</table>
<?php
$h->endpage();
?>
Link to comment
Share on other sites

Untested.

Change array, line 70.

<?php

require "globals.php";

if ($_GET['time'])
{
 $time=$_GET['time'];
}
else
{
 $time=15;
}
$cn=0;
$lk=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-1440*60");
$aa=mysql_num_rows($lk);
$ll=mysql_query("SELECT * FROM users WHERE laston>unix_timestamp()-60*60");
$ab=mysql_num_rows($ll);
$lm=mysql_query("SELECT `userid`,`gang`,`username`,`user_level`,`donator_days`,`last_login` FROM users WHERE laston>unix_timestamp()-45*60");
$ac=mysql_num_rows($lm);
$ln=mysql_query("SELECT `userid`,`gang`,`username`,`user_level`,`donator_days`,`last_login` FROM users WHERE laston>unix_timestamp()-30*60");
$ad=mysql_num_rows($ln);
$lo=mysql_query("SELECT `userid`,`gang`,`username`,`user_level`,`donator_days`,`last_login` FROM users WHERE laston>unix_timestamp()-15*60");
$ae=mysql_num_rows($lo);
$he=mysql_query("SELECT `userid`,`gang`,`username`,`user_level`,`donator_days`,`last_login` FROM users WHERE laston>unix_timestamp()-1*60");
$hu=mysql_num_rows($he);
$q=mysql_query("SELECT `userid`,`gang`,`username`,`user_level`,`donator_days`,`last_login` FROM users WHERE laston>unix_timestamp()-{$time}*60 ORDER BY laston DESC");
?>
<table width=30% cellpading='1' cellspacing='0' border=0 align=left>
 <tr>
   <td>
     <b>Time Selector</b>
      </td></tr>
     <td>
     <a href='usersonline.php?time=1'>(1 Min)</a>
     <a href='usersonline.php?time=15'>(15 Mins)</a>
     <a href='usersonline.php?time=30'>(30 Mins)</a>
     <a href='usersonline.php?time=45'>(45 Mins)</a>
     <a href='usersonline.php?time=60'">(60 Mins)</a>
     <a href='usersonline.php?time=1440'>(24 Hours)</a>  
   </td>
   </tr>

<table width=50% cellpading='1' cellspacing='0' border=0 align=left>
   <tr>
      <td class=table>
           <h3></h3>

       <td class=table>
           <b>Gang</b>
       </td>
       <td class=table>
           <b><center>User</center></b>
       </td>
       <td>

       <td class=table>
           <b>Time Online</b>
       </td>
       <td class=table>
           <b>Action</b>
       </td>
   </tr>
<?php
$donator = null;
$owner = null;
$staff = null;

$colours = array(); /* Yeah, I'm english. This is how we spell it */
/* Change the values, add more if need be */
$colours[1] = '#000000';
$colours[2] = '#000000';
$colours[3] = '#000000';
$colours[4] = '#000000';


           while($r=mysql_fetch_assoc($q))
           {
             $la=time()-$r['laston'];
             $unit="secs";
             if($la >= 60)
             {
               $la=(int) ($la/60);
               $unit="mins";
             }
             if($la >= 60)
             {
               $la=(int) ($la/60);
               $unit="hours";
               if($la >= 24)
               {
                 $la=(int) ($la/24);
                 $unit="days";
               }
             }
             $cn++;

$name=$r['username'];
$gangtag=$r['yourgangPREF'];

if($r['donatordays'] > 0) {
$donator="<img src='donator.gif' width='9%' height='9%' alt='Donator: {$r['donatordays']} Days Left' title='Donator: {$r['donatordays']} Days Left' />";
} 

if($r['user_level'] == 2) { /* staff is anyone with user_level > 1, perhaps change == */
$staff="<img src='staff.gif' width='8%' height='8%' alt='Game Staff' title='Staff' />";
}
if($r['userid']==1) {
$owner="OWNER"; /* put something for owner here */
}

$r['username']="<a href='viewuser.php?u={$r['userid']}'><span style='color: {$colours[$r['user_level']]};'>$name</span> $owner $donator $staff</a>";

             print "<tr>
                      <td class=table>
                        $cn.
                      </td>
                      <td class=table >";
                      if ($r['gang'] > 0) {
                      print"
                        <a href='gangs.php?action=view&ID={$r['gang']}'><small>[View]</small></a>
                      </td>";
                      }
                      else {
                       print"
                        <small>No Gang</small>
                      </td>";
                      }
                      print"
                      <td class=table>
                        {$r['username']}
                      </td>
                      <td class=table>
                      ($la $unit) 
                      </td>
                      <td class=table>";
             $lb=time()-$r['last_login'];
             $units="secs";
             if($lb >= 60)
             {
               $lb=(int) ($lb/60);
               $units="mins";
             }
             if($lb >= 60)
             {
               $lb=(int) ($lb/60);
               $units="hours";
               if($lb >= 24)
               {
                 $lb=(int) ($lb/24);
                 $units="days";
               }
             }
             if($r['laston'] <= time()-15*15)
             {
               $lb="offline";
               $unit="";
             }
              print "{$lb} {$units}</td>";
             if($r['hospital'] > 0) {
             print"<td><small>Hospital</small></td>";
             }
              if($r['jail'] > 0) {
             print"<td><small>Jail</small></td>";
             }
              if($r['hospital'] == 0 AND $r['jail'] == 0) {
             print"<td><small>[<a href='attack.php?uid={$r['userid']}'>Attack</a>]</td>";
             }
             print"</tr>";
      } 

?>
   </td>
 </tr>
</table>
<table width=30% class='colortd' cellpading='1' cellspacing='0' border=0 align=left>
   <tr>
   <td class=table>
     <b>Statistics</b>
     Users online in the last minute: <?php print"{$hu}"; ?>
     Users online in the last 15 minutes: <?php print"{$ae}"; ?>
     Users online in the last 30 minutes: <?php print"{$ad}"; ?>
     Users online in the last 45 minutes: <?php print"{$ac}"; ?>
     Users online in the last hour: <?php print"{$ab}"; ?>
     Users online in the last 24 hours: <?php print"{$aa}"; ?>
   </td>
 <tr>
</table>
<table width=30% class='colortd' cellpading='1' cellspacing='0' border=0 align=left>
   <tr>
   <td class=table>
     <b>Legend</b>
     Admins = <font color=gold>Gold</font>
     Secretaries = <font color=blue>Blue</font> 
     Assistants = <font color=purple>Purple</font>
     Members = <font color=silver>Silver</font>
     Staff = <img src='staff.gif'></img>
     Donators = <img src='donator.gif'></img>
   </td>
 <tr>
</table>
<?php
$h->endpage();
?>
Edited by sniko
Link to comment
Share on other sites

Change include "globals.php"; to include 'globals.php';

That does nothing but the speed diff which is pointless for a game.

Why not just make a func?

<?php #for the pretty colors
function username($userid)
{
global $db, $ir, $h, $_GET, $_POST, $r;
$query = $db->query("SELECT username,user_level,userid,donatordays FROM users WHERE userid = " . $userid);
if ($db->num_rows($query)) {
	$user_data = $db->fetch_row($query);
	if ($user_data['user_level'] == 2) {
		$user_data['username'] = "<font color='#gold'>" . $user_data['username'] . "</font></a> [{$r['userid']}] <img src='/images/donator.gif' alt='Donator: {$r['donatordays']} Days Left' title='VIP: {$r['donatordays']} Days Left' />";
	} elseif ($user_data['user_level'] == 3) {
		$user_data['username'] = "<font color='Blue'>" . $user_data['username'] . "</font></a> [{$r['userid']}] <img src='/images/donator.gif' alt='Donator: {$r['donatordays']} Days Left' title='VIP: {$r['donatordays']} Days Left' />";
	} elseif ($user_data['user_level'] == 4) {
		$user_data['username'] = "<font color=' Purple '>" . $user_data['username'] . "</font></a> [{$r['userid']}] <img src='/images/donator.gif' alt='Donator: {$r['donatordays']} Days Left' title='VIP: {$r['donatordays']} Days Left' />";
	} elseif ($user_data['donatordays'] > 0) {
		$user_data['username'] = "<font color='red'>" . $user_data['username'] . "</font></a> [{$r['userid']}] <img src='/images/donator.gif' alt='Donator: {$r['donatordays']} Days Left' title='VIP: {$r['donatordays']} Days Left' />";
	} else {
		$user_data['username'] = "<font color='#fff'>" . $user_data['username'] . "</font> [{$r['userid']}]</a>";
	}
	return $user_data['username'];
} else {
	return false;
}
}
?>

 

so for the username be something like this

".username($r['userid'])."

 

Benefit of this is you can use it numerous amounts of time without having to add the whole array and whatnot to the file itself :)

Edited by bladewolf2010
added something
Link to comment
Share on other sites

Cool, thanks blade, seems like your function works in my global_func.php :D But I'm having trouble where add this ".username($r['userid'])." in my original usersonline.php (1st page)?

Change:

$name=$r['username'];

to:

$name=username($r['userid']);

Where you have....

<td class=table>

{$r['username']}

change to <td class=table>{$name}

Edited by lucky3809
Link to comment
Share on other sites

Opps, sorry about that.

the global line can actually be shorten to

global $db,$r;

 

Sorry about that, dunno what I was thinking on that.

Just wondering, I'm not really needing this, but ideas on how to some sort of record? So I track most online ever in the last 15 mins, hour, 30 mins, and day?

Thanks again, guys, exactly what I wanted. :D

Link to comment
Share on other sites

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.   Paste as plain text instead

  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...