The Coder Posted September 13, 2012 Share Posted September 13, 2012 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(); ?> Quote Link to comment Share on other sites More sharing options...
sniko Posted September 13, 2012 Share Posted September 13, 2012 (edited) 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 September 13, 2012 by sniko Quote Link to comment Share on other sites More sharing options...
The Coder Posted September 14, 2012 Author Share Posted September 14, 2012 Doesn't seem to work, but thanks alot for trying Sniko. :( Any help please? Quote Link to comment Share on other sites More sharing options...
sniko Posted September 14, 2012 Share Posted September 14, 2012 Doesn't seem to work, but thanks alot for trying Sniko. :( Any help please? What part "doesn't seem to work" Quote Link to comment Share on other sites More sharing options...
The Coder Posted September 14, 2012 Author Share Posted September 14, 2012 What part "doesn't seem to work" Error ): Parse error: syntax error, unexpected T_REQUIRE in /home/infamous/public_html/usersonline.php on line 3 Thanks for helping Sniko Quote Link to comment Share on other sites More sharing options...
sniko Posted September 14, 2012 Share Posted September 14, 2012 I don't believe that is an error on my part Quote Link to comment Share on other sites More sharing options...
Uridium Posted September 14, 2012 Share Posted September 14, 2012 the coder i tested Snikos version and didnt get the error your getting ? Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted September 14, 2012 Share Posted September 14, 2012 perhaps you may have deleted something while editing copy and paste sniko's code again, works on my end also with no problem.... usually a ' or ; is missing when you get that error type.... Quote Link to comment Share on other sites More sharing options...
Uridium Posted September 14, 2012 Share Posted September 14, 2012 Could be a copy and paste issue from here usually i have to click on edit post when grabbing to copy and paste cos if i dont and try the normal approach i end up with everything on line 1 Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted September 15, 2012 Share Posted September 15, 2012 Change include "globals.php"; to include 'globals.php'; Quote Link to comment Share on other sites More sharing options...
bladewolf2010 Posted September 15, 2012 Share Posted September 15, 2012 (edited) 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 September 15, 2012 by bladewolf2010 added something Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted September 15, 2012 Share Posted September 15, 2012 (edited) Yep I use something similar... http://makewebgames.io/showthread.php/29865-mccode-Small-Mod-%29 Edited September 15, 2012 by lucky3809 Quote Link to comment Share on other sites More sharing options...
The Coder Posted September 15, 2012 Author Share Posted September 15, 2012 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)? Quote Link to comment Share on other sites More sharing options...
lucky3809 Posted September 15, 2012 Share Posted September 15, 2012 (edited) 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 September 15, 2012 by lucky3809 Quote Link to comment Share on other sites More sharing options...
The Coder Posted September 15, 2012 Author Share Posted September 15, 2012 Change: $name=$r['username']; to: $name=username($r['userid']); Where you have.... <td class=table> {$r['username']} change to <td class=table>{$name} Thanks to all who helped, works exactly how I wanted it, thanks all!:D Quote Link to comment Share on other sites More sharing options...
bladewolf2010 Posted September 15, 2012 Share Posted September 15, 2012 Always glad to help the community out here and there. It's where I learned, when I did, was a bit harsher but, meh. It helped me greatly. Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted September 15, 2012 Share Posted September 15, 2012 really $_GET, $_POST as a global Quote Link to comment Share on other sites More sharing options...
bladewolf2010 Posted September 15, 2012 Share Posted September 15, 2012 (edited) 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. Edited September 15, 2012 by bladewolf2010 Quote Link to comment Share on other sites More sharing options...
The Coder Posted September 15, 2012 Author Share Posted September 15, 2012 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 Quote Link to comment Share on other sites More sharing options...
bladewolf2010 Posted September 15, 2012 Share Posted September 15, 2012 Create a table in the DB for records of what you want $q=$db->query("SELECT * FROM records WHERE recid=1",$c); $v=$db->fetch_row($q); $fifteen=$db->num_rows($q); if ($v['rec15']<$fifteen) {$db->query("UPDATE records SET rec15=$fifteen WHERE recid=1",$c);} something link that Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.