Legendary Battlemage
- Joined
- Aug 16, 2008
- Messages
- 600
- Reaction score
- 259
Alright, I didn't do anything last night cause I went out. ANYWAY.
I've created the function to show people who are online, including a pagination to limit the number of people shown, per page.
I'm probably going to review the code for this, but in the mean time, it is what it is.
Quick review of the code and I've added the latest member function inside, I was planning to do this already. I just wanted to make sure the first part of the code was correct (and working)
I've created the function to show people who are online, including a pagination to limit the number of people shown, per page.
PHP:
public static function users ($ID = NULL)
{
GLOBAL $config, $db;
$query = ('SELECT count(ID) FROM users WHERE online = "1"');
if ($statement = $db->prepare($query))
{
$statement->execute();
$statement->bind_result($id);
$rows = array();
while ($statement->fetch())
{
$rows[] = array('id' => $id);
}
$statement->close();
$rows = $id;
$pages = ceil($rows / 10);
for ($i = 1; $i <= $pages; $i++)
{
$result2 .= '<a href="'.$config['www']['url'].'?p=users&sub='.$i.'" target="_self">'.$i.'</a>';
}
}
$query = ('SELECT username, look FROM users WHERE online = "1" ORDER BY username ASC LIMIT '.(($ID - 1) * 10).', 10');
if ($statement = $db->prepare($query))
{
$statement->execute();
$statement->bind_result($username, $look);
while ($statement->fetch())
{
$class = ($x % 2 == 0) ? 'odd' : 'even';
$result1 .= ('<a href="'.$config['www']['url'].'?p=home&sub='.$username.'" target="_self" class="'.$class.'">
<div class="users-image"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure='.$look.'&direction=2&head_direction=2&size=s&gesture=sml.gif" alt="'.$username.'" /></div>
<div class="users-p"><b>'.$username.'</b><br />Online</div>
</a>');
$x++;
}
$statement->close();
}
return ('<div class="container-title orange">'.$config['www']['name'].'s online</div>
<div class="container-body">
'.$result1.'
<div class="container-body-form">Pages: '.$result2.'</div>
</div>');
}
I'm probably going to review the code for this, but in the mean time, it is what it is.
Quick review of the code and I've added the latest member function inside, I was planning to do this already. I just wanted to make sure the first part of the code was correct (and working)
PHP:
public static function users ($ID = NULL)
{
GLOBAL $config, $db;
if ($ID == NULL) // LATEST MEMBER
{
$query = ('SELECT username, look FROM users ORDER BY ID DESC LIMIT 1');
if ($statement = $db->prepare($query))
{
$statement->execute();
$statement->bind_result($username, $look);
$statement->fetch();
$statement->close();
}
return ('<a href="'.$config['www']['url'].'?p=home&sub='.$username.'" target="_self" class="odd">
<div class="users-image" style="width: 80px;"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure='.$look.'&direction=2&head_direction=2&size=s&gesture=sml.gif" alt="'.$username.'" /></div>
<div class="users-p" style="width: 178px;"><b>'.$username.'</b><br />Latest Member</div>
</a>');
}
else // USERS ONLINE
{
$query = ('SELECT username, look FROM users WHERE online = "1" ORDER BY username ASC LIMIT '.(($ID - 1) * 10).', 10');
if ($statement = $db->prepare($query))
{
$statement->execute();
$statement->bind_result($username, $look);
while ($statement->fetch())
{
$class = ($x % 2 == 0) ? 'odd' : 'even';
$result1 .= ('<a href="'.$config['www']['url'].'?p=home&sub='.$username.'" target="_self" class="'.$class.'">
<div class="users-image"><img src="http://www.habbo.nl/habbo-imaging/avatarimage?figure='.$look.'&direction=2&head_direction=2&size=s&gesture=sml.gif" alt="'.$username.'" /></div>
<div class="users-p"><b>'.$username.'</b><br />Online</div>
</a>');
$x++;
}
$statement->close();
}
$query = ('SELECT count(ID) FROM users WHERE online = "1"');
$count = array();
if ($statement = $db->prepare($query))
{
$statement->execute();
$statement->bind_result($id);
while ($statement->fetch())
{
$count[] = array('id' => $id);
}
$statement->close();
$pages = ceil($count = $id / 10);
for ($i = 1; $i <= $pages; $i++)
{
$result2 .= '<a href="'.$config['www']['url'].'?p=users&sub='.$i.'" target="_self">'.$i.'</a>';
}
}
return ('<div class="container-title orange">'.$config['www']['name'].'s online</div>
<div class="container-body">
'.$result1.'
<div class="container-body-form">Pages: '.$result2.'</div>
</div>');
}
}