[Script] PHP Ranking Script

Results 1 to 6 of 6
  1. #1
    Arrogant Wizard DeathArt is offline
    MemberRank
    Mar 2007 Join Date
    StockholmLocation
    2,657Posts

    [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(
       
    => 'Knight',
       
    => 'Mage',
       
    => '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>
    Last edited by DeathArt; 14-10-07 at 05:06 PM.


  2. #2
    Proficient Member FredyKiller is offline
    MemberRank
    Oct 2006 Join Date
    192Posts

    Re: [Script] PHP Ranking Script

    Thx for sharing that script. as u said ultra simple.

  3. #3
    Account Upgraded | Title Enabled! L3gend is offline
    MemberRank
    Dec 2006 Join Date
    United KingdomLocation
    208Posts

    Re: [Script] PHP Ranking Script

    Thanks for sharing :)

  4. #4
    Valued Member Pure_evil is offline
    MemberRank
    Sep 2006 Join Date
    111Posts

    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)

  5. #5
    boo General is offline
    MemberRank
    Sep 2006 Join Date
    at homeLocation
    2,269Posts

    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

  6. #6
    Arrogant Wizard DeathArt is offline
    MemberRank
    Mar 2007 Join Date
    StockholmLocation
    2,657Posts

    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 ;-)



Advertisement