Guest User

Untitled

a guest
Aug 12th, 2018
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.64 KB | None | 0 0
  1. <?php
  2.  
  3. // multi-dimensional array holding info for achievements
  4. $data = array
  5. (
  6.     0=>array
  7.     (
  8.         "1337", // achievement name
  9.         "Be online at 13:37", // description
  10.         1 // objective value (value set at completion)
  11.     ),
  12.     1=>array
  13.     (
  14.         "Addict",
  15.         "Connect 500 times",
  16.         500
  17.     )
  18. );
  19.  
  20. // mysql initzializing variables
  21. $hostname = "localhost";
  22. $username = "root";
  23. $password = "pass";
  24. $database = "achievement_api";
  25.  
  26. // connect to mysql
  27. $connection = mysql_connect( $hostname, $username, $password );
  28. if( !$connection )
  29. {
  30.     // could not connect; throw error
  31.  
  32.     die( 'Could not connect: ' . mysql_error( ) );
  33. }
  34.  
  35. // check if steamid was entered
  36. $steamid = $_GET['steamid'];
  37. if( !$steamid )
  38. {
  39.     // no steamid; throw error
  40.  
  41.     die( 'No steamid entered!' );
  42. }
  43.  
  44. // html body / style
  45. echo "<html>";
  46. echo "<style>";
  47. echo "body{margin:0;padding:0;font-family:Tahoma,Helvetica,Arial,sans-serif;}table,tr,td{align:center;color:#222;background:#fff;margin:1;padding:1;border:solid #eee 1px;}";
  48. echo "</style>";
  49. echo "<body>";
  50. // table (for the sake of simplicity)
  51. echo "<table width=600>";
  52. echo "<tr><td><b>Achievement Name</b></td><td><b>Description</b></td><td><b>Earned</b></td></tr>";
  53.  
  54. // select database in sql
  55. mysql_select_db( $database, $connection );
  56.  
  57. // make the query
  58. $query = "SELECT `data`, `key2` FROM `achievement_api_ex` WHERE `key1` = '$steamid';";
  59. // send query
  60. $result = mysql_query( $query, $connection );
  61. // check if query picked up any data
  62. if( !$result )
  63. {
  64.     // no data found
  65.  
  66.     die( 'No data found!' );
  67. }
  68.  
  69. // achievement counter
  70. $achievement = 0;
  71.  
  72. // achievements earned
  73. $achievements = 0;
  74.  
  75. // fetch data from query
  76. while( $row = mysql_fetch_array( $result ) )
  77. {
  78.     // convert data to an int
  79.     $number = (int)$row['data'];
  80.     // check if data is more or equal to the max value (assigned in multi-dimensional array above)
  81.     $earned = ( ( $number >= $data[$achievement][2] ) ? "Yes" : "No" ); // "Yes" if more or equal, otherwise "No"
  82.     // check if client has earned
  83.     if( $earned == "Yes" )
  84.     {
  85.         $achievements++;
  86.     }
  87.      
  88.     // print the data into the table
  89.     echo "<tr><td>". $data[$achievement][0] ."</td><td>" . $data[$achievement][1] . "</td><td>" . $earned . "</td></tr>";
  90.      
  91.     // increment the achievement variable
  92.     $achievement++;
  93. }
  94.  
  95. // total achievements earned
  96. echo "Achievements Earned: " . $achievements ."<br>";
  97. echo "Max Achievements: " . $achievement . "";
  98.  
  99. // close
  100. echo "</table>";
  101. echo "</body>";
  102.  
  103. ?>
Add Comment
Please, Sign In to add comment