[Script] PHP Ranking Script
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 Code:
<?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 Code:
<!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>
Re: [Script] PHP Ranking Script
Thx for sharing that script. as u said ultra simple.
Re: [Script] PHP Ranking Script
Re: [Script] PHP Ranking Script
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)
Re: [Script] PHP Ranking Script
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
Re: [Script] PHP Ranking Script
hehe, I forgot that in this one. I'll update it now, thanks.
I used the double order on HOAX ;-)