Advertisement
HackerRIZLA

How to make a leaderboard for KillAnnouncer!

Sep 22nd, 2012
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.76 KB | None | 0 0
  1. In this tutorial, we're going to learn how to make a leaderboard for KillAnnouncer!
  2. Let's get started. It is recommended that you know basic PHP and HTML/CSS in order to follow
  3. this tutorial. A source download will be avaialable at the end of this tutorial.
  4.  
  5. After setting up KillAnnouncer, you'll see that it automatically fills a table with 4 rows. These
  6. rows include "PlayerName", "Kills","Deaths", and "Ratio".
  7.  
  8. We're going to need that information laters so keep it handy somewhere.
  9.  
  10.  
  11. _-Connecting to the database-_
  12. Connecting to a mysql database via php is easy, simple open the connection.
  13.  
  14. [code PHP]
  15. <?php
  16. $hostname = ''; //Your mysql hostname, usually localhost
  17. $username = ''; //your mysql username
  18. $password = ''; //your mysql password
  19. $database = ''; //your mysql database name
  20.  
  21. $con = mysql_connect($hostname, $username, $password);
  22. if (!$con){ //If the connection failed...
  23. die('Could not connect! Error:'.mysql_error()); //display error
  24. } //end if statement
  25. ?>
  26. [/code PHP]
  27.  
  28. That will allow you to connect to the database. Now if you're going to be using mysql throughout
  29. your website, I suggest you save this in another file named db.connect.inc.php. If you're not
  30. going to be using mysql alot and you just need it for the leaderboard, keep it in leaderboard.php
  31.  
  32. Now go ahead and start making the table for your leaderboard.
  33.  
  34. [code PHP]
  35. <table class="table table-striped">
  36. <thead>
  37. <tr>
  38. <th>K/D Ratio</th>
  39. <th>Username</th>
  40. <th>Kills</th>
  41. <th>Deaths</th>
  42. </tr>
  43. </thead>
  44. <tbody>
  45. </tbody>
  46. </table>
  47. [/code PHP]
  48.  
  49. Now that we've got our table all settled, let's go ahead and add some php to get the info from the
  50. datbase and display it.
  51.  
  52. [code PHP]
  53. <tbody>
  54. <?php
  55. $sql ="SELECT * FROM leaderboard ORDER BY 'Ration'";
  56. $res = mysql_query($sql);
  57. while ($row = mysql_fetch_array($res)) {
  58. echo "<tr>";
  59. echo "<td>".$row['Ratio']."</td>";
  60. echo "<td>".$row['PlayerName']."</td>";
  61. echo "<td>".$row['Kills']."</td>";
  62. echo "<td>".$row['Deaths']."</td>";
  63. echo "</tr>";
  64. }
  65. ?>
  66. </tbody>
  67. [/code PHP]
  68.  
  69. The code above spits out those rows for each row in the datbase, It's a loop that will display all
  70. the enterys in the database.
  71.  
  72. This is what your whole page should look like...
  73.  
  74.  
  75. [code PHP]
  76.  
  77. <?php
  78. $hostname = ''; //Your mysql hostname, usually localhost
  79. $username = ''; //your mysql username
  80. $password = ''; //your mysql password
  81. $database = ''; //your mysql database name
  82.  
  83. $con = mysql_connect($hostname, $username, $password);
  84. if (!$con){ //If the connection failed...
  85. die('Could not connect! Error:'.mysql_error()); //display error
  86. } //end if statement
  87. ?>
  88. <html>
  89. <head>
  90. <title>KillAnnouncer Leaderboard</title>
  91. </head>
  92. <body>
  93. <table class="table table-striped">
  94. <thead>
  95. <tr>
  96. <th>K/D Ratio</th>
  97. <th>Username</th>
  98. <th>Kills</th>
  99. <th>Deaths</th>
  100. </tr>
  101. </thead>
  102. <tbody>
  103. <?php
  104. $sql ="SELECT * FROM leaderboard ORDER BY 'Ration'";
  105. $res = mysql_query($sql);
  106. while ($row = mysql_fetch_array($res)) {
  107. echo "<tr>";
  108. echo "<td>".$row['Ratio']."</td>";
  109. echo "<td>".$row['PlayerName']."</td>";
  110. echo "<td>".$row['Kills']."</td>";
  111. echo "<td>".$row['Deaths']."</td>";
  112. echo "</tr>";
  113. }
  114. ?>
  115. </tbody>
  116. </table>
  117. </body>
  118. </html>
  119. [/code PHP]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement