Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // multi-dimensional array holding info for achievements
- $data = array
- (
- 0=>array
- (
- "1337", // achievement name
- "Be online at 13:37", // description
- 1 // objective value (value set at completion)
- ),
- 1=>array
- (
- "Addict",
- "Connect 500 times",
- 500
- )
- );
- // mysql initzializing variables
- $hostname = "localhost";
- $username = "root";
- $password = "pass";
- $database = "achievement_api";
- // connect to mysql
- $connection = mysql_connect( $hostname, $username, $password );
- if( !$connection )
- {
- // could not connect; throw error
- die( 'Could not connect: ' . mysql_error( ) );
- }
- // check if steamid was entered
- $steamid = $_GET['steamid'];
- if( !$steamid )
- {
- // no steamid; throw error
- die( 'No steamid entered!' );
- }
- // html body / style
- echo "<html>";
- echo "<style>";
- 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;}";
- echo "</style>";
- echo "<body>";
- // table (for the sake of simplicity)
- echo "<table width=600>";
- echo "<tr><td><b>Achievement Name</b></td><td><b>Description</b></td><td><b>Earned</b></td></tr>";
- // select database in sql
- mysql_select_db( $database, $connection );
- // make the query
- $query = "SELECT `data`, `key2` FROM `achievement_api_ex` WHERE `key1` = '$steamid';";
- // send query
- $result = mysql_query( $query, $connection );
- // check if query picked up any data
- if( !$result )
- {
- // no data found
- die( 'No data found!' );
- }
- // achievement counter
- $achievement = 0;
- // achievements earned
- $achievements = 0;
- // fetch data from query
- while( $row = mysql_fetch_array( $result ) )
- {
- // convert data to an int
- $number = (int)$row['data'];
- // check if data is more or equal to the max value (assigned in multi-dimensional array above)
- $earned = ( ( $number >= $data[$achievement][2] ) ? "Yes" : "No" ); // "Yes" if more or equal, otherwise "No"
- // check if client has earned
- if( $earned == "Yes" )
- {
- $achievements++;
- }
- // print the data into the table
- echo "<tr><td>". $data[$achievement][0] ."</td><td>" . $data[$achievement][1] . "</td><td>" . $earned . "</td></tr>";
- // increment the achievement variable
- $achievement++;
- }
- // total achievements earned
- echo "Achievements Earned: " . $achievements ."<br>";
- echo "Max Achievements: " . $achievement . "";
- // close
- echo "</table>";
- echo "</body>";
- ?>
Add Comment
Please, Sign In to add comment