Dec 30, 2014 05:57 PM
(This post was last modified: Dec 31, 2014 12:49 PM by Nozemi™.)
I'm trying to make a highscores page for my RSPS, however, I don't want to include the admin and developer groups. Also I like the ability to exclude usernames. So I made this function, which obviously doesn't work, I understand why, but I'm stuck with how to solve it at the moment. I have been sitting with this highscores for too many hours straight now to think straight.
Above is my current function. If anyone could help me solve this while I'm too tired, it would be greatly appreciated!
Solution:
The above function is what I ended up with. It could likely be improved slightly, but it works just fine bor me I believe.
Thanks to TOPMOBBSS for his help I could combine some of his code with my code. I really appreciate everyones attempt to assist me out!
PHP Code
<?php
public function get_top_players($skill) {
global $db;
$C = new Classes;
$query = "
SELECT
MAX($skill),
username,
usergroup
FROM mybb_users
";
$query_params = array(
//':skill' => $skill
);
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch(PDOException $ex) {
die($ex->getMessage());
}
$row = $stmt->fetch();
$level = $C->get_level($row[$skill]);
if(!in_array($row['usergroup'], $this->exclude_groups)) {
if(!in_array($row['username'], $this->exclude_users)) {
echo '<td class="trow1" align="center"><span class="smalltext"><strong>'.$row['username'].'</strong></span></td>'."\r\n";
echo '<td class="trow1" align="center"><span class="smalltext"><strong>'.$level.'</strong></span></td>'."\r\n";
}
}
}
Above is my current function. If anyone could help me solve this while I'm too tired, it would be greatly appreciated!
Solution:
PHP Code
<?php
public function get_top_players($skill) {
global $db;
$C = new Classes;
if($skill == 'm_total' || $skill == 's_total') {
if($skill == 'm_total') {
$skill = 'totalxp';
$query = "
SELECT
max($skill),
totalxp,
total,
username,
usergroup
FROM mybb_users
WHERE `usergroup` NOT IN (". implode(',', $this->exclude_groups) .")
AND `username` NOT IN (". implode(',', array_map('Classes::quote_string', $this->exclude_users)) .")
";
} elseif($skill == 's_total') {
$skill = 'totalxp';
$query = "
SELECT
max($skill),
totalxp,
total,
username,
usergroup
FROM mybb_users
WHERE `usergroup` NOT IN (". implode(',', $this->exclude_groups) .")
AND `username` NOT IN (". implode(',', array_map('Classes::quote_string', $this->exclude_users)) .")
AND `combat` = 3
";
}
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch(PDOException $ex) {
die($ex->getMessage());
}
$row = $stmt->fetch();
echo '<td class="trow1" align="center"><span class="smalltext"><strong><a href="#">'.$row['username'].'</a></strong></span></td>'."\r\n";
echo '<td class="trow1" align="center"><span class="smalltext"><strong>'.$row['total'].'</strong></span></td>'."\r\n";
} else {
$query = "
SELECT
max($skill),
$skill,
username,
usergroup
FROM mybb_users
WHERE `usergroup` NOT IN (". implode(',', $this->exclude_groups) .")
AND `username` NOT IN (". implode(',', array_map('Classes::quote_string', $this->exclude_users)) .")
";
try {
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch(PDOException $ex) {
die($query.'<br />'.$ex->getMessage());
}
$row = $stmt->fetch();
$level = $C->get_level($row[$skill]);
echo '<td class="trow1" align="center"><span class="smalltext"><strong><a href="#">'.$row['username'].'</a></strong></span></td>'."\r\n";
echo '<td class="trow1" align="center"><span class="smalltext"><strong>'.$level.'</strong></span></td>'."\r\n";
}
The above function is what I ended up with. It could likely be improved slightly, but it works just fine bor me I believe.
Thanks to TOPMOBBSS for his help I could combine some of his code with my code. I really appreciate everyones attempt to assist me out!


![[Image: eldrios-small.png]](https://cdn.discordapp.com/attachments/119513373216866304/668831710657380362/eldrios-small.png)

![[Image: JQvMLdi.gif]](https://i.imgur.com/JQvMLdi.gif)