• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

[Script] PHP Ranking Script

Arrogant Wizard
Loyal Member
Joined
Mar 30, 2007
Messages
745
Reaction score
34
Ultra simple ranking script, easy to build more on, and customize the layout of.
Uses ODBC, so easier than fiddeling with MSSQL.

ranking.php
PHP:
<?php

// configuration
$config = array(
    'db_username' => 'sa', // database username
    'db_password' => '',   // database password
    'db_dsn'      => 'hoax',   // system DSN to the database
    'template'    => 'ranking.tpl',  // registration template path/filename
);

$conn = odbc_connect(
    $config['db_dsn'],
    $config['db_username'],
    $config['db_password']
);

$classes = array(
   0 => 'Knight',
   1 => 'Mage',
   2 => 'Archer'
);

$sql = "SELECT 
            Player.Level,
            Player.Class,
            Player.Name,
            Guild.Name AS GuildName
        FROM
            Player
        LEFT JOIN
            Guild
        ON
            Guild.GID = Player.GID
        WHERE
            Player.Admin = 0
        ORDER BY
            Player.Level DESC,Player.Exp DESC
";

class Player {}

$players = array();

$exec = odbc_exec($conn,$sql);

while($data = odbc_fetch_array($exec))
{
    $player = new Player();
    $player->Name  = $data['Name'];
    $player->Level = $data['Level'];
    $player->Guild = $data['GuildName'];
    $player->ClassName = $classes[$data['Class']];
    $players[] = $player;
}

require_once($config['template']);

?>

ranking.tpl
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title> Ranking  </title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
      body {
          font-family: verdana;
          font-size: 11px;
      }
    </style>
  </head>
  <body>
    <form action="" method="post">
      <table>
        <thead>
        <tr>
          <th>Level</th>
          <th>Name</th>
          <th>Class</th>
          <th>Guild</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach($players as $player): ?>
        <tr>
          <td><?php echo $player->Level; ?></td>
          <td><?php echo $player->Name; ?></td>
          <td><?php echo $player->ClassName; ?></td>
          <td><?php echo $player->Guild; ?></td>
        </tr>
        <?php endforeach; ?>
        </tbody>
      </table>
    </form>
  </body>
</html>
 
Last edited:
Newbie Spellweaver
Joined
Sep 25, 2006
Messages
36
Reaction score
0
took me a minute or 5 to figure out how to connect to that odbc (total php and everything related to it noob) but anyone with some brains should be able to figure that out :)

thx for sharing

(not that i actually use those things, i just try to get em to work and understand how they work)
 
Joined
Sep 10, 2006
Messages
1,243
Reaction score
179
Not really correct, since you don't order on Exp... So maybe the nr1 will have lower Exp , but will be before other people of same level with more Exp.

so replace

ORDER BY Player.Level DESC

to

ORDER BY Player.Level DESC, Player.Exp DESC
 
Arrogant Wizard
Loyal Member
Joined
Mar 30, 2007
Messages
745
Reaction score
34
hehe, I forgot that in this one. I'll update it now, thanks.

I used the double order on HOAX ;-)
 
Back
Top