• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
  • 2026 staff recruitment is open! Check it out and consider applying!

Web Page Highscores.php filter vocation

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
c8P52Xd.png


How to do to, vocation's bar work?
(ZNOTE AAC)

highscores.php
Code:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';

if ($config['log_ip']) {
znote_visitor_insert_detailed_data(3);
}

// Fetch highscore type
$voc = (isset($_GET['vocation'])) ? (int)getValue($_GET['vocation']) : 5;
$type = (isset($_GET['type'])) ? (int)getValue($_GET['type']) : 7;
if ($type > 9) $type = 7;

// Fetch highscore page
$page = getValue(@$_GET['page']);
if (!$page || $page == 0) $page = 1;
else $page = (int)$page;

$highscore = $config['highscore'];

$rows = $highscore['rows'];
$rowsPerPage = $highscore['rowsPerPage'];

function skillName($type) {
$types = array(
1 => "Club",
2 => "Sword",
3 => "Axe",
4 => "Distance",
5 => "Shield",
6 => "Fish",
7 => "Experience", // Hardcoded
8 => "Magic Level", // Hardcoded
9 => "Fist", // Since 0 returns false I will make 9 = 0. :)
);
return $types[(int)$type];
}

function pageCheck($index, $page, $rowPerPage) {
return ($index < ($page * $rowPerPage) && $index >= ($page * $rowPerPage) - $rowPerPage) ? true : false;
}

$cache = new Cache('engine/cache/highscores');
if ($cache->hasExpired()) {
$scores = fetchAllScores($rows, $config['TFSVersion'], $highscore['ignoreGroupId']);

$cache->setContent($scores);
$cache->save();
} else {
$scores = $cache->load();
}

if ($scores) {
?>
<h1>Ranking for <?php echo skillName($type); ?>.</h1>
<form action="" method="GET">
<select name="type">
<option value="7" <?php if ($type == 7) echo "selected"; ?>>Experience</option>
<option value="8" <?php if ($type == 8) echo "selected"; ?>>Magic</option>
<option value="5" <?php if ($type == 5) echo "selected"; ?>>Shield</option>
<option value="2" <?php if ($type == 2) echo "selected"; ?>>Sword</option>
<option value="1" <?php if ($type == 1) echo "selected"; ?>>Club</option>
<option value="3" <?php if ($type == 3) echo "selected"; ?>>Axe</option>
<option value="4" <?php if ($type == 4) echo "selected"; ?>>Distance</option>
<option value="6" <?php if ($type == 6) echo "selected"; ?>>Fish</option>
<option value="9" <?php if ($type == 9) echo "selected"; ?>>Fist</option>
</select>
<select name="page">
<?php
$pages = (int)($highscore['rows'] / $highscore['rowsPerPage']);
for ($i = 0; $i < $pages; $i++) {
$x = $i + 1;
if ($x == $page) echo "<option value='".$x."' selected>Page: ".$x."</option>";
else echo "<option value='".$x."'>Page: ".$x."</option>";
}
?>
</select>
<select name="vocation">
<option value="0" <?php if ($voc == 0) echo "selected"; ?>>No-Vocation</option>
<option value="1" <?php if ($voc == 1) echo "selected"; ?>>Sorcerer</option>
<option value="2" <?php if ($voc == 2) echo "selected"; ?>>Druid</option>
<option value="3" <?php if ($voc == 3) echo "selected"; ?>>Paladin</option>
<option value="4" <?php if ($voc == 4) echo "selected"; ?>>Knight</option>
<option value="5" <?php if ($voc == 5) echo "selected"; ?>>All</option>
</select>
<input type="submit" value=" View " class="btn btn-info">
</form>
<table id="highscoresTable" class="table table-striped table-hover">
<tr class="yellow">
<td>Rank</td>
<td>Name</td>
<td>Vocation</td>
<td>Level</td>
<?php if ($type === 7) echo "<td>Points</td>"; ?>
</tr>
<?php
for ($i = 0; $i < count($scores[$type]); $i++) {
if (pageCheck($i, $page, $rowsPerPage)) {
?>
<tr>
<td><?php echo $i+1; ?></td>
<td><a href="characterprofile.php?name=<?php echo $scores[$type][$i]['name']; ?>"><?php echo $scores[$type][$i]['name']; ?></a></td>
<td><?php echo vocation_id_to_name($scores[$type][$i]['vocation']); ?></td>
<td><?php echo $scores[$type][$i]['value']; ?></td>
<?php if ($type === 7) echo "<td>". $scores[$type][$i]['experience'] ."</td>"; ?>
</tr>
<?php
}
}
?>
</table>
<?php
}
include 'layout/overall/footer.php'; ?>
 
This whole page could be written better but you see where it says this?
Code:
  <select name="vocation">
  <option value="0" <?php if ($voc == 0) echo "selected"; ?>>No-Vocation</option>
  <option value="1" <?php if ($voc == 1) echo "selected"; ?>>Sorcerer</option>
  <option value="2" <?php if ($voc == 2) echo "selected"; ?>>Druid</option>
  <option value="3" <?php if ($voc == 3) echo "selected"; ?>>Paladin</option>
  <option value="4" <?php if ($voc == 4) echo "selected"; ?>>Knight</option>
  <option value="5" <?php if ($voc == 5) echo "selected"; ?>>All</option>
  </select>

This code above is a mixture of php and html

Where it says <option value="0", 0 is the vocation id for no vocation or none, same thing below it <option value="1" corresponds with the sorcerer vocation, <option value="2" corresponds with the druid, <option value="3" with the paladin vocation, <option value="4" with the knight vocation.
All of what I just explained is just HTML

Anywhere you see other code encapsulated or surrounded by <?php /* code is in here */ ?> is PHP which is executed off the server and the value it contains will be printed in HTML

Lets break it apart
Code:
<option value="0"  -- html
   <?php if ($voc == 0) echo "selected"; ?> -- php
   >No-Vocation</option> -- html

I can't exactly teach you the languages or concepts you will need to read about them on their respective websites
A good place to start is http://www.w3schools.com
 
This whole page could be written better but you see where it says this?
Code:
  <select name="vocation">
  <option value="0" <?php if ($voc == 0) echo "selected"; ?>>No-Vocation</option>
  <option value="1" <?php if ($voc == 1) echo "selected"; ?>>Sorcerer</option>
  <option value="2" <?php if ($voc == 2) echo "selected"; ?>>Druid</option>
  <option value="3" <?php if ($voc == 3) echo "selected"; ?>>Paladin</option>
  <option value="4" <?php if ($voc == 4) echo "selected"; ?>>Knight</option>
  <option value="5" <?php if ($voc == 5) echo "selected"; ?>>All</option>
  </select>

This code above is a mixture of php and html

Where it says <option value="0", 0 is the vocation id for no vocation or none, same thing below it <option value="1" corresponds with the sorcerer vocation, <option value="2" corresponds with the druid, <option value="3" with the paladin vocation, <option value="4" with the knight vocation.
All of what I just explained is just HTML

Anywhere you see other code encapsulated or surrounded by <?php /* code is in here */ ?> is PHP which is executed off the server and the value it contains will be printed in HTML

Lets break it apart
Code:
<option value="0"  -- html
   <?php if ($voc == 0) echo "selected"; ?> -- php
   >No-Vocation</option> -- html

I can't exactly teach you the languages or concepts you will need to read about them on their respective websites
A good place to start is http://www.w3schools.com


He did change it, but now, he need a SQL filter to show only players per vocation
 
Replace:

PHP:
if (pageCheck($i, $page, $rowsPerPage)) {

With

PHP:
$continue = true;
if($voc != 5 && (($voc == 0 && $scores[$type][$i]['vocation'] != 0) || ($voc != $scores[$type][$i]['vocation'] && $voc + 4 != $scores[$type][$i]['vocation']))) {
    $continue = false;
}
if ($continue && pageCheck($i, $page, $rowsPerPage)) {

but it will be probably not working fine, it will display only vocations from the current row. You need to paste here the fetch function from your engine, then i can add the vocation part.
 
Replace:

PHP:
if (pageCheck($i, $page, $rowsPerPage)) {

With

PHP:
$continue = true;
if($voc != 5 && (($voc == 0 && $scores[$type][$i]['vocation'] != 0) || ($voc != $scores[$type][$i]['vocation'] && $voc + 4 != $scores[$type][$i]['vocation']))) {
    $continue = false;
}
if ($continue && pageCheck($i, $page, $rowsPerPage)) {

but it will be probably not working fine, it will display only vocations from the current row. You need to paste here the fetch function from your engine, then i can add the vocation part.

I dont understand u so much, i have a bad english, sorry :(

But so ty to try help, but dont work :\

Code:
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\highscores.php on line 122

122
Code:
include 'layout/overall/footer.php'; ?>

highscores.php (i try)
Code:
<?php require_once 'engine/init.php'; include 'layout/overall/header.php';

if ($config['log_ip']) {
znote_visitor_insert_detailed_data(3);
}

// Fetch highscore type
$voc = (isset($_GET['vocation'])) ? (int)getValue($_GET['vocation']) : 5;
$type = (isset($_GET['type'])) ? (int)getValue($_GET['type']) : 7;
if ($type > 9) $type = 7;

// Fetch highscore page
$page = getValue(@$_GET['page']);
if (!$page || $page == 0) $page = 1;
else $page = (int)$page;

$highscore = $config['highscore'];

$rows = $highscore['rows'];
$rowsPerPage = $highscore['rowsPerPage'];

function skillName($type) {
$types = array(
1 => "Club",
2 => "Sword",
3 => "Axe",
4 => "Distance",
5 => "Shield",
6 => "Fish",
7 => "Experience", // Hardcoded
8 => "Magic Level", // Hardcoded
9 => "Fist", // Since 0 returns false I will make 9 = 0. :)
);
return $types[(int)$type];
}

function pageCheck($index, $page, $rowPerPage) {
return ($index < ($page * $rowPerPage) && $index >= ($page * $rowPerPage) - $rowPerPage) ? true : false;
}

$cache = new Cache('engine/cache/highscores');
if ($cache->hasExpired()) {
$scores = fetchAllScores($rows, $config['TFSVersion'], $highscore['ignoreGroupId']);

$cache->setContent($scores);
$cache->save();
} else {
$scores = $cache->load();
}

if ($scores) {
?>
<h1>Ranking for <?php echo skillName($type); ?>.</h1>
<form action="" method="GET">
<select name="type">
<option value="7" <?php if ($type == 7) echo "selected"; ?>>Experience</option>
<option value="8" <?php if ($type == 8) echo "selected"; ?>>Magic</option>
<option value="5" <?php if ($type == 5) echo "selected"; ?>>Shield</option>
<option value="2" <?php if ($type == 2) echo "selected"; ?>>Sword</option>
<option value="1" <?php if ($type == 1) echo "selected"; ?>>Club</option>
<option value="3" <?php if ($type == 3) echo "selected"; ?>>Axe</option>
<option value="4" <?php if ($type == 4) echo "selected"; ?>>Distance</option>
<option value="6" <?php if ($type == 6) echo "selected"; ?>>Fish</option>
<option value="9" <?php if ($type == 9) echo "selected"; ?>>Fist</option>
</select>
<select name="page">
<?php
$pages = (int)($highscore['rows'] / $highscore['rowsPerPage']);
for ($i = 0; $i < $pages; $i++) {
$x = $i + 1;
if ($x == $page) echo "<option value='".$x."' selected>Page: ".$x."</option>";
else echo "<option value='".$x."'>Page: ".$x."</option>";
}
?>
</select>
<select name="vocation">
<option value="0" <?php if ($voc == 0) echo "selected"; ?>>No-Vocation</option>
<option value="1" <?php if ($voc == 1) echo "selected"; ?>>Sorcerer</option>
<option value="2" <?php if ($voc == 2) echo "selected"; ?>>Druid</option>
<option value="3" <?php if ($voc == 3) echo "selected"; ?>>Paladin</option>
<option value="4" <?php if ($voc == 4) echo "selected"; ?>>Knight</option>
<option value="5" <?php if ($voc == 5) echo "selected"; ?>>All</option>
</select>
<input type="submit" value=" View " class="btn btn-info">
</form>

<table id="highscoresTable" class="table table-striped table-hover">
<tr class="yellow">
<td>Rank</td>
<td>Name</td>
<td>Vocation</td>
<td>Level</td>
<?php if ($type === 7) echo "<td>Points</td>"; ?>
</tr>
<?php
for ($i = 0; $i < count($scores[$type]); $i++) {
if (pageCheck($i, $page, $rowsPerPage)) {
   
   
 $continue = true;
if($voc != 5 && (($voc == 0 && $scores[$type][$i]['vocation'] != 0) || ($voc != $scores[$type][$i]['vocation'] && $voc + 4 != $scores[$type][$i]['vocation']))) {
  $continue = false;
}
if ($continue && pageCheck($i, $page, $rowsPerPage)) {
   
   
?>
<tr>
<td><?php echo $i+1; ?></td>
<td><a href="characterprofile.php?name=<?php echo $scores[$type][$i]['name']; ?>"><?php echo $scores[$type][$i]['name']; ?></a></td>
<td><?php echo vocation_id_to_name($scores[$type][$i]['vocation']); ?></td>
<td><?php echo $scores[$type][$i]['value']; ?></td>
<?php if ($type === 7) echo "<td>". $scores[$type][$i]['experience'] ."</td>"; ?>
</tr>
<?php
}
}
?>
</table>
<?php
}
include 'layout/overall/footer.php'; ?>
 
PHP:
<?php
    require_once 'engine/init.php';
    include 'layout/overall/header.php';

    if ($config['log_ip']) {
        znote_visitor_insert_detailed_data(3);
    }

    // Fetch highscore type
    $voc = (isset($_GET['vocation'])) ? (int)getValue($_GET['vocation']) : 5;
    $type = (isset($_GET['type'])) ? (int)getValue($_GET['type']) : 7;
  
    if ($type > 9) $type = 7;
  
    // Fetch highscore page
    $page = getValue(@$_GET['page']);
    $page = (!$page || $page == 0) ? 1 : (int)$page;

    $highscore = $config['highscore'];
    $rows = $highscore['rows'];
    $rowsPerPage = $highscore['rowsPerPage'];

    function skillName($type) {
        $types = array(
            1 => "Club",
            2 => "Sword",
            3 => "Axe",
            4 => "Distance",
            5 => "Shield",
            6 => "Fish",
            7 => "Experience", // Hardcoded
            8 => "Magic Level", // Hardcoded
            9 => "Fist", // Since 0 returns false I will make 9 = 0. :)
        );
        return $types[(int)$type];
    }

    function pageCheck($index, $page, $rowPerPage) {
        return ($index < ($page * $rowPerPage) && $index >= ($page * $rowPerPage) - $rowPerPage) ? true : false;
    }

    $cache = new Cache('engine/cache/highscores');
    if ($cache->hasExpired()) {
        $scores = fetchAllScores($rows, $config['TFSVersion'], $highscore['ignoreGroupId']);
        $cache->setContent($scores);
        $cache->save();
    } else {
        $scores = $cache->load();
    }

    if ($scores) {
?>
        <h1>Ranking for <?php echo skillName($type); ?>.</h1>
        <form action="" method="GET">
            <select name="type">
                <option value="7" <?php if ($type == 7) echo "selected"; ?>>Experience</option>
                <option value="8" <?php if ($type == 8) echo "selected"; ?>>Magic</option>
                <option value="5" <?php if ($type == 5) echo "selected"; ?>>Shield</option>
                <option value="2" <?php if ($type == 2) echo "selected"; ?>>Sword</option>
                <option value="1" <?php if ($type == 1) echo "selected"; ?>>Club</option>
                <option value="3" <?php if ($type == 3) echo "selected"; ?>>Axe</option>
                <option value="4" <?php if ($type == 4) echo "selected"; ?>>Distance</option>
                <option value="6" <?php if ($type == 6) echo "selected"; ?>>Fish</option>
                <option value="9" <?php if ($type == 9) echo "selected"; ?>>Fist</option>
            </select>
            <select name="page">
            <?php
                $pages = (int)($highscore['rows'] / $highscore['rowsPerPage']);
                for ($i = 0; $i < $pages; $i++) {
                    $x = $i + 1;
                    if ($x == $page)
                        echo "<option value='".$x."' selected>Page: ".$x."</option>";
                    else
                        echo "<option value='".$x."'>Page: ".$x."</option>";
                }
            ?>
            </select>
            <select name="vocation">
                <option value="0" <?php if ($voc == 0) echo "selected"; ?>>No-Vocation</option>
                <option value="1" <?php if ($voc == 1) echo "selected"; ?>>Sorcerer</option>
                <option value="2" <?php if ($voc == 2) echo "selected"; ?>>Druid</option>
                <option value="3" <?php if ($voc == 3) echo "selected"; ?>>Paladin</option>
                <option value="4" <?php if ($voc == 4) echo "selected"; ?>>Knight</option>
                <option value="5" <?php if ($voc == 5) echo "selected"; ?>>All</option>
            </select>
            <input type="submit" value=" View " class="btn btn-info">
        </form>

        <table id="highscoresTable" class="table table-striped table-hover">
            <tr class="yellow">
                <td>Rank</td>
                <td>Name</td>
                <td>Vocation</td>
                <td>Level</td>
        <?php if ($type === 7) echo "<td>Points</td>"; ?>
            </tr>
        <?php
            for ($i = 0; $i < count($scores[$type]); $i++) {
                if (pageCheck($i, $page, $rowsPerPage)) {
                    $continue = true;
                    if($voc != 5 && (($voc == 0 && $scores[$type][$i]['vocation'] != 0) || ($voc != $scores[$type][$i]['vocation'] && $voc + 4 != $scores[$type][$i]['vocation']))) {
                        $continue = false;
                    }
                    if ($continue && pageCheck($i, $page, $rowsPerPage)) {
        ?>
                        <tr>
                            <td><?php echo $i+1; ?></td>
                            <td><a href="characterprofile.php?name=<?php echo $scores[$type][$i]['name']; ?>"><?php echo $scores[$type][$i]['name']; ?></a></td>
                            <td><?php echo vocation_id_to_name($scores[$type][$i]['vocation']); ?></td>
                            <td><?php echo $scores[$type][$i]['value']; ?></td>
                        <?php if ($type === 7) echo "<td>". $scores[$type][$i]['experience'] ."</td>"; ?>
                        </tr>
        <?php
                        }
                }
            }
        ?>
        </table>
<?php
    }
    include 'layout/overall/footer.php';
?>
 
Last edited:
PHP:
<?php
    require_once 'engine/init.php';
    include 'layout/overall/header.php';

    if ($config['log_ip']) {
        znote_visitor_insert_detailed_data(3);
    }

    // Fetch highscore type
    $voc = (isset($_GET['vocation'])) ? (int)getValue($_GET['vocation']) : 5;
    $type = (isset($_GET['type'])) ? (int)getValue($_GET['type']) : 7;
 
    if ($type > 9) $type = 7;
 
    // Fetch highscore page
    $page = getValue(@$_GET['page']);
    $page = (!$page || $page == 0) ? 1 : (int)$page;

    $highscore = $config['highscore'];
    $rows = $highscore['rows'];
    $rowsPerPage = $highscore['rowsPerPage'];

    function skillName($type) {
        $types = array(
            1 => "Club",
            2 => "Sword",
            3 => "Axe",
            4 => "Distance",
            5 => "Shield",
            6 => "Fish",
            7 => "Experience", // Hardcoded
            8 => "Magic Level", // Hardcoded
            9 => "Fist", // Since 0 returns false I will make 9 = 0. :)
        );
        return $types[(int)$type];
    }

    function pageCheck($index, $page, $rowPerPage) {
        return ($index < ($page * $rowPerPage) && $index >= ($page * $rowPerPage) - $rowPerPage) ? true : false;
    }

    $cache = new Cache('engine/cache/highscores');
    if ($cache->hasExpired()) {
        $scores = fetchAllScores($rows, $config['TFSVersion'], $highscore['ignoreGroupId']);
        $cache->setContent($scores);
        $cache->save();
    } else {
        $scores = $cache->load();
    }

    if ($scores) {
?>
        <h1>Ranking for <?php echo skillName($type); ?>.</h1>
        <form action="" method="GET">
            <select name="type">
                <option value="7" <?php if ($type == 7) echo "selected"; ?>>Experience</option>
                <option value="8" <?php if ($type == 8) echo "selected"; ?>>Magic</option>
                <option value="5" <?php if ($type == 5) echo "selected"; ?>>Shield</option>
                <option value="2" <?php if ($type == 2) echo "selected"; ?>>Sword</option>
                <option value="1" <?php if ($type == 1) echo "selected"; ?>>Club</option>
                <option value="3" <?php if ($type == 3) echo "selected"; ?>>Axe</option>
                <option value="4" <?php if ($type == 4) echo "selected"; ?>>Distance</option>
                <option value="6" <?php if ($type == 6) echo "selected"; ?>>Fish</option>
                <option value="9" <?php if ($type == 9) echo "selected"; ?>>Fist</option>
            </select>
            <select name="page">
            <?php
                $pages = (int)($highscore['rows'] / $highscore['rowsPerPage']);
                for ($i = 0; $i < $pages; $i++) {
                    $x = $i + 1;
                    if ($x == $page)
                        echo "<option value='".$x."' selected>Page: ".$x."</option>";
                    else
                        echo "<option value='".$x."'>Page: ".$x."</option>";
                }
            ?>
            </select>
            <select name="vocation">
                <option value="0" <?php if ($voc == 0) echo "selected"; ?>>No-Vocation</option>
                <option value="1" <?php if ($voc == 1) echo "selected"; ?>>Sorcerer</option>
                <option value="2" <?php if ($voc == 2) echo "selected"; ?>>Druid</option>
                <option value="3" <?php if ($voc == 3) echo "selected"; ?>>Paladin</option>
                <option value="4" <?php if ($voc == 4) echo "selected"; ?>>Knight</option>
                <option value="5" <?php if ($voc == 5) echo "selected"; ?>>All</option>
            </select>
            <input type="submit" value=" View " class="btn btn-info">
        </form>

        <table id="highscoresTable" class="table table-striped table-hover">
            <tr class="yellow">
                <td>Rank</td>
                <td>Name</td>
                <td>Vocation</td>
                <td>Level</td>
        <?php if ($type === 7) echo "<td>Points</td>"; ?>
            </tr>
        <?php
            for ($i = 0; $i < count($scores[$type]); $i++) {
                if (pageCheck($i, $page, $rowsPerPage)) {
                    $continue = true;
                    if($voc != 5 && (($voc == 0 && $scores[$type][$i]['vocation'] != 0) || ($voc != $scores[$type][$i]['vocation'] && $voc + 4 != $scores[$type][$i]['vocation']))) {
                        $continue = false;
                    }
                    if ($continue && pageCheck($i, $page, $rowsPerPage)) {
        ?>
                        <tr>
                            <td><?php echo $i+1; ?></td>
                            <td><a href="characterprofile.php?name=<?php echo $scores[$type][$i]['name']; ?>"><?php echo $scores[$type][$i]['name']; ?></a></td>
                            <td><?php echo vocation_id_to_name($scores[$type][$i]['vocation']); ?></td>
                            <td><?php echo $scores[$type][$i]['value']; ?></td>
                        <?php if ($type === 7) echo "<td>". $scores[$type][$i]['experience'] ."</td>"; ?>
                        </tr>
        <?php
                        }
                }
            }
        ?>
        </table>
<?php
    }
    include 'layout/overall/footer.php';
?>


So ty!!! It's work! :D
 
Back
Top