Jump to content
MakeWebGames

Recommended Posts

Posted

Hey guys

Having abit of trouble with a code.

Problem:

When clicking on USERSONLINE.PHP no user appear to come up.

 

If i click FIVE MINS it shows how many people were on in the last 5 Minutes.

 

I Was wondering could any one help me with this? :D

 

BTW Found on MWG, Edited by Jordan - Pudda

 

<?php
require ("globals.php");
switch($_GET['online'])
{
case 'fiveminutes': fiveminutes(); break;
case 'thirtyminutes': thirtyminutes(); break;
case 'onehour': onehour(); break;
case 'oneday': oneday(); break;
default: index(); break;
}
function index()
{
print "
<table width='90%' border='1' height='20'>
<tr>
	<th><u>[url='usersonline.php?online=fiveminutes']Five Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=thirtyminutes']Thirty Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=onehour']One Hour[/url]</u></th>
	<th><u>[url='usersonline.php?online=oneday']One Day[/url]</u></th>
</tr>
</table>";
}
function fiveminutes()
{
global $db;
print "
<table width='90%' border='1' height='20'>
<tr>
	<th><u>[url='usersonline.php?online=fiveminutes']Five Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=thirtyminutes']Thirty Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=onehour']One Hour[/url]</u></th>
	<th><u>[url='usersonline.php?online=oneday']One Day[/url]</u></th>
</tr>
</table>";
echo "<table width='90%' border='1' height='20'>
<tr>
	<th height='6'><u>Order</u></th>
	<th><u>Name</u></th>
	<th><u>ID</u></th>
	<th><u>Level</u></th>
	<th><u>Gender<u/></th>
	<th><u>Last Action<u/></th>
	<th><u>Money</u></th>
	<th><u>Attack</u></th>
</tr>";
$q=$db->query("SELECT `username`,`userid`,`laston`,`gender`,`money`,`level` FROM users WHERE laston>unix_timestamp()-5*60 ORDER BY laston DESC");
while($r=mysql_fetch_array($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";
}	}
if($r['laston'] > 0)	{
$la=time()-$r['laston'];
$unit="seconds";
if($la >= 60)	{
$la=(int) ($la/60);
$unit="minutes";
}
if($la >= 60)	{
$la=(int) ($la/60);
$unit="hours";
if($la >= 24)	{
$la=(int) ($la/24);
$unit="days";
}	}
$str="$la $unit ago";
 } else {
$str="--";
}
if($r['last_login'] > 0)	{
$ll=time()-$r['last_login'];
$unit2="seconds";
if($ll >= 60)	{
$ll=(int) ($ll/60);
$unit2="minutes";
}
if($ll >= 60)	{
$ll=(int) ($ll/60);
$unit2="hours";
if($ll >= 24)	{
$ll=(int) ($ll/24);
$unit2="days";
}
}
$str2="$ll $unit2 ago";
 } else {
$str2="--";
}
$cn++;
echo "<tr>
	<th>$cn.</th>
	<th>[url='viewuser.php?u=".$r[']".rasheed($r['username'])."[/url]</th>
	<th>".rasheed($r['userid'])."</th>
	<th>".rasheed($r['level'])."</th>
	<th>".$r['gender']."</th>
	<th>$str</th>
	<th>$".rasheed($r['money'])."</th>
	<th><a href='attack.php?ID=".$r['userid']."'>Attack ".$r['gender']." ";
if($r['gender'] == 'Female')
{
	echo "her";
}
else
{
	echo "him";
}
	echo "</a></th>
</tr>";
}
echo "</table>";}
function thirtyminutes()
{
global $db;
print "
<table width='90%' border='1' height='20'>
<tr>
	<th><u>[url='usersonline.php?online=fiveminutes']Five Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=thirtyminutes']Thirty Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=onehour']One Hour[/url]</u></th>
	<th><u>[url='usersonline.php?online=oneday']One Day[/url]</u></th>
</tr>
</table>";
echo "<table width='90%' border='1' height='20'>
<tr>
	<th height='6'><u>Order</u></th>
	<th><u>Name</u></th>
	<th><u>ID</u></th>
	<th><u>Level</u></th>
	<th><u>Gender<u/></th>
	<th><u>Last Action<u/></th>
	<th><u>Money</u></th>
	<th><u>Attack</u></th>
</tr>";
$q=$db->query("SELECT `username`,`userid`,`laston`,`gender`,`money`,`level` FROM users WHERE laston>unix_timestamp()-30*60 ORDER BY laston DESC");
while($r=mysql_fetch_array($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";
}	}
if($r['laston'] > 0)	{
$la=time()-$r['laston'];
$unit="seconds";
if($la >= 60)	{
$la=(int) ($la/60);
$unit="minutes";
}
if($la >= 60)	{
$la=(int) ($la/60);
$unit="hours";
if($la >= 24)	{
$la=(int) ($la/24);
$unit="days";
}	}
$str="$la $unit ago";
 } else {
$str="--";
}
if($r['last_login'] > 0)	{
$ll=time()-$r['last_login'];
$unit2="seconds";
if($ll >= 60)	{
$ll=(int) ($ll/60);
$unit2="minutes";
}
if($ll >= 60)	{
$ll=(int) ($ll/60);
$unit2="hours";
if($ll >= 24)	{
$ll=(int) ($ll/24);
$unit2="days";
}
}
$str2="$ll $unit2 ago";
 } else {
$str2="--";
}
$cn++;
echo "<tr>
			<th>$cn.</th>
	<th>[url='viewuser.php?u=".$r[']".rasheed($r['username'])."[/url]</th>
	<th>".rasheed($r['userid'])."</th>
	<th>".rasheed($r['level'])."</th>
	<th>".$r['gender']."</th>
	<th>$str</th>
	<th>$".rasheed($r['money'])."</th>
	<th><a href='attack.php?ID=".$r['userid']."'>Attack ".$r['gender']." ";
if($r['gender'] == 'Female')
{
	echo "her";
}
else
{
	echo "him";
}
	echo "</a></th>
</tr>";
}
echo "</table>";}
function onehour()
{
global $db;
print "
<table width='90%' border='1' height='20'>
<tr>
	<th><u>[url='usersonline.php?online=fiveminutes']Five Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=thirtyminutes']Thirty Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=onehour']One Hour[/url]</u></th>
	<th><u>[url='usersonline.php?online=oneday']One Day[/url]</u></th>
</tr>
</table>";
echo "<table width='90%' border='1' height='20'>
<tr>
	<th height='6'><u>Order</u></th>
	<th><u>Name</u></th>
	<th><u>ID</u></th>
	<th><u>Level</u></th>
	<th><u>Gender<u/></th>
	<th><u>Last Action<u/></th>
	<th><u>Money</u></th>
	<th><u>Attack</u></th>
</tr>";
$q=$db->query("SELECT `username`,`userid`,`laston`,`gender`,`money`,`level` FROM users WHERE laston>unix_timestamp()-60*60 ORDER BY laston DESC");
while($r=mysql_fetch_array($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";
}	}
if($r['laston'] > 0)	{
$la=time()-$r['laston'];
$unit="seconds";
if($la >= 60)	{
$la=(int) ($la/60);
$unit="minutes";
}
if($la >= 60)	{
$la=(int) ($la/60);
$unit="hours";
if($la >= 24)	{
$la=(int) ($la/24);
$unit="days";
}	}
$str="$la $unit ago";
 } else {
$str="--";
}
if($r['last_login'] > 0)	{
$ll=time()-$r['last_login'];
$unit2="seconds";
if($ll >= 60)	{
$ll=(int) ($ll/60);
$unit2="minutes";
}
if($ll >= 60)	{
$ll=(int) ($ll/60);
$unit2="hours";
if($ll >= 24)	{
$ll=(int) ($ll/24);
$unit2="days";
}
}
$str2="$ll $unit2 ago";
 } else {
$str2="--";
}
$cn++;
echo "	<th>$cn.</th>
	<th>[url='viewuser.php?u=".$r[']".rasheed($r['username'])."[/url]</th>
	<th>".rasheed($r['userid'])."</th>
	<th>".rasheed($r['level'])."</th>
	<th>".$r['gender']."</th>
	<th>$str</th>
	<th>$".rasheed($r['money'])."</th>
	<th><a href='attack.php?ID=".$r['userid']."'>Attack ".$r['gender']." ";
if($r['gender'] == 'Female')
{
	echo "her";
}
else
{
	echo "him";
}
	echo "</a></th>
</tr>";
}
echo "</table>";}
function oneday()
{
global $db;
print "
<table width='90%' border='1' height='20'>
<tr>
	<th><u>[url='usersonline.php?online=fiveminutes']Five Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=thirtyminutes']Thirty Minutes[/url]</u></th>
	<th><u>[url='usersonline.php?online=onehour']One Hour[/url]</u></th>
	<th><u>[url='usersonline.php?online=oneday']One Day[/url]</u></th>
</tr>
</table>";
echo "<table width='90%' border='1' height='20'>
<tr>
	<th height='6'><u>Order</u></th>
	<th><u>Name</u></th>
	<th><u>ID</u></th>
	<th><u>Level</u></th>
	<th><u>Gender<u/></th>
	<th><u>Last Action<u/></th>
	<th><u>Money</u></th>
	<th><u>Attack</u></th>
</tr>";
$q=$db->query("SELECT `username`,`userid`,`laston`,`gender`,`money`,`level` FROM users WHERE laston>unix_timestamp()-1440*60 ORDER BY laston DESC");
while($r=mysql_fetch_array($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";
}	}
if($r['laston'] > 0)	{
$la=time()-$r['laston'];
$unit="seconds";
if($la >= 60)	{
$la=(int) ($la/60);
$unit="minutes";
}
if($la >= 60)	{
$la=(int) ($la/60);
$unit="hours";
if($la >= 24)	{
$la=(int) ($la/24);
$unit="days";
}	}
$str="$la $unit ago";
 } else {
$str="--";
}
if($r['last_login'] > 0)	{
$ll=time()-$r['last_login'];
$unit2="seconds";
if($ll >= 60)	{
$ll=(int) ($ll/60);
$unit2="minutes";
}
if($ll >= 60)	{
$ll=(int) ($ll/60);
$unit2="hours";
if($ll >= 24)	{
$ll=(int) ($ll/24);
$unit2="days";
}
}
$str2="$ll $unit2 ago";
 } else {
$str2="--";
}
$cn++;
echo "<tr>
	<th>$cn.</th>
	<th>[url='viewuser.php?u=".$r[']".rasheed($r['username'])."[/url]</th>
	<th>".rasheed($r['userid'])."</th>
	<th>".rasheed($r['level'])."</th>
	<th>".$r['gender']."</th>
	<th>$str</th>
	<th>$".rasheed($r['money'])."</th>
	<th><a href='attack.php?ID=".$r['userid']."'>Attack ".$r['gender']." ";
if($r['gender'] == 'Female')
{
	echo "her";
}
else
{
	echo "him";
}
	echo "</a></th>
</tr>";
}
echo "</table>";}
$h->endpage();
?>

 

Cheers, Rasheed :D

Posted
function index()
{
print "
<table width='90%' border='1' height='20'>
   <tr>
       <th><u>[url='usersonline.php?online=fiveminutes']Five Minutes[/url]</u></th>
       <th><u>[url='usersonline.php?online=thirtyminutes']Thirty Minutes[/url]</u></th>
       <th><u>[url='usersonline.php?online=onehour']One Hour[/url]</u></th>
       <th><u>[url='usersonline.php?online=oneday']One Day[/url]</u></th>
   </tr>
</table>";
}

 

The default for the file doesn't make a call to display anything other than the links...

Posted

Yeah i know.

While speaking to Pudda on MSN i said that to him and adding / $q=$db->query("SELECT `username`,`userid`,`laston`,`gender`,`money`,`level` FROM users WHERE laston>unix_timestamp()-5*60 ORDER BY laston DESC");

He just replied back.

Phail. :P

Somthing about

 

case 'fiveminutes': fiveminutes(); break;
case 'thirtyminutes': thirtyminutes(); break;
case 'onehour': onehour(); break;
case 'oneday': oneday(); break;
default: index(); break;

 

The right function or somthing? :rolleyes:

Posted

Here try this

 

<?php
require "globals.php";

print "
<table width='90%' border='1' height='20'>
   <tr>
       <th><u>[url='usersonline.php?l=5']Five Minutes[/url]</u></th>
       <th><u>[url='usersonline.php?l=30']Thirty Minutes[/url]</u></th>
       <th><u>[url='usersonline.php?l=60']One Hour[/url]</u></th>
       <th><u>[url='usersonline.php?l=1440']One Day[/url]</u></th>
   </tr>
</table>";

echo "<table width='90%' border='1' height='20'>
   <tr>
       <th height='6'><u>Order</u></th>
       <th><u>Name</u></th>
       <th><u>ID</u></th>
       <th><u>Level</u></th>
       <th><u>Gender<u/></th>
       <th><u>Last Action<u/></th>
       <th><u>Money</u></th>
       <th><u>Attack</u></th>
   </tr>";

// $_GET['l'] is the length in minutes that you want to check	
if(isset($_GET['l'])) 
{ 
	$len = abs((int)$_GET['l']); 
}
else 
{ 
	$len = 5; 
}
$len = time() - $len * 60;

$q=$db->query("SELECT `username`,`userid`,`laston`,`gender`,`money`,`level` FROM users WHERE laston>$len ORDER BY laston DESC");
while($r=mysql_fetch_array($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";
   }    }
if($r['laston'] > 0)    {
$la=time()-$r['laston'];
$unit="seconds";
if($la >= 60)    {
$la=(int) ($la/60);
$unit="minutes";
   }
if($la >= 60)    {
$la=(int) ($la/60);
$unit="hours";
if($la >= 24)    {
$la=(int) ($la/24);
$unit="days";
   }    }
$str="$la $unit ago";
 } else {
$str="--";
   }
if($r['last_login'] > 0)    {
$ll=time()-$r['last_login'];
$unit2="seconds";
if($ll >= 60)    {
$ll=(int) ($ll/60);
$unit2="minutes";
   }
if($ll >= 60)    {
$ll=(int) ($ll/60);
$unit2="hours";
if($ll >= 24)    {
$ll=(int) ($ll/24);
$unit2="days";
   }
   }
$str2="$ll $unit2 ago";
 } else {
$str2="--";
   }
$cn++;
echo "<tr>
       <th>$cn.</th>
       <th>[url='viewuser.php?u=".$r[']".rasheed($r['username'])."[/url]</th>
       <th>".rasheed($r['userid'])."</th>
       <th>".rasheed($r['level'])."</th>
       <th>".$r['gender']."</th>
       <th>$str</th>
       <th>$".rasheed($r['money'])."</th>
       <th><a href='attack.php?ID=".$r['userid']."'>Attack ".$r['gender']." ";
if($r['gender'] == 'Female')
   {
       echo "her";
   }
   else
   {
       echo "him";
   }
       echo "</a></th>
   </tr>";
   }
echo "</table>";

$h->endpage();
?>
Posted

Lol sorry pudda. Plus i told you on MSN. :huh:

Call to a member function query() on a non-object in /home/chaotic/public_html/usersonline.php on line 45

Nope. :( :( ):

Posted
<?php
include(DIRNAME(__FILE__) . '/globals.php');
$_GET['time'] = isset($_GET['time']) && is_string($_GET['time']) ? strtolower(trim($_GET['time'])) : false;
if($_GET['time'] == 'fiveminutes') {
$time = 300;
} else if($_GET['time'] == 'thirtyminutes') {
$time = 1800;
} else if($_GET['time'] == 'onehour') {
$time = 3600;
} else {
$time = 86400;
}
echo "<table width='90%' border='1' height='20' class='table'>
<tr>
<th><u>[url='usersonline.php?online=fiveminutes']Five Minutes[/url]</u></th>
<th><u>[url='usersonline.php?online=thirtyminutes']Thirty Minutes[/url]</u></th>
<th><u>[url='usersonline.php?online=onehour']One Hour[/url]</u></th>
<th><u>[url='usersonline.php?online=oneday']One Day[/url]</u></th>
</tr>
</table>";
echo "<table width='90%' border='1' height='20' class='table'>
<tr style='text-decoration:underline;'>
<th height='6'>Order</th>
<th>Name</th>
<th>ID</th>
<th>Level</th>
<th>Gender</th>
<th>Last Action</th>
<th>Money</th>
<th>Attack</th>
</tr>";
$q = $db->query("SELECT `username`,`userid`,`laston`,`gender`,`money`,`level` FROM users WHERE laston > (unix_timestamp() - ".$time.") ORDER BY laston DESC");
while($r = $db->fetch_row($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"; }
}
if($r['laston'] > 0) {
$unit = "seconds";
if($la >= 60) { $la = (int) ($la / 60); $unit = "minutes"; }
if($la >= 60) { $la = (int) ($la / 60); $unit = "hours";
if($la >= 24) { $la = (int) ($la / 24); $unit = "days"; }
}
$str = $la." ".$unit." ago";
} else {
$str = "--";
}

if($r['last_login'] > 0) {
$ll = time() - $r['last_login'];
$unit2 = "seconds";
if($ll >= 60) { $ll = (int) ($ll / 60); $unit2 = "minutes"; }
if($ll >= 60) { $ll = (int) ($ll / 60); $unit2 = "hours";
if($ll >= 24) { $ll = (int) ($ll / 24); $unit2 = "days"; }
}
$str2 = $ll." ".$unit2." ago";
} else {
$str2 = "--";
}
$cn++;
echo "<tr>
<th>".$cn."</th>
<th>[url='viewuser.php?u=".$r[']".rasheed($r['username'])."[/url]</th>
<th>".rasheed($r['userid'])."</th>
<th>".rasheed($r['level'])."</th>
<th>".$r['gender']."</th>
<th>".$str."</th>
<th>\$".rasheed($r['money'])."</th>
<th><a href='attack.php?ID=".$r['userid']."'>Attack ";
echo ($r['gender'] == 'Female') ? "her" : "him";
echo "</a></th>
</tr>";
}
echo "</table>";

$h->endpage();
?>

 

Untested, but should work fine

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