name $keys[3]->type { $fields=""; foreach($keys as $key) { $fields .= "`$key->name` " . $key->type . ' NOT NULL,'; } $query = "CREATE TABLE `$login` ( `name` VARCHAR(32) NOT NULL, `score` INT NOT NULL, `clientid` INT NOT NULL, $fields `timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP) TYPE=MyISAM;"; mysql_query($query) or die ("error: tabel creation: ".mysql_error()); } function deleteHighscoreTable($login) { mysql_query("DROP TABLE `$login`") or die ("error: drop table: ".mysql_error()); } function highscoreTableStatus($login) { //----------- $sql = mysql_query("SELECT count(*) AS count FROM $login") or die ("error: counting highscore entries: ".mysql_error()); $dat = mysql_fetch_array($sql); $highscorecount = $dat["count"]; $result = "Status for game $login: $highscorecount highscore entries "; //----------- $sql = mysql_query("SELECT count(*) AS count FROM serverlist WHERE game=\"$login\"") or die ("error: counting active servers: ".mysql_error()); $dat = mysql_fetch_array($sql); $servercount = $dat["count"]; $result .= "and $servercount active servers.
\n"; //----------- $result.= '
    '; $sql = mysql_query("SELECT * FROM $login LIMIT 0") or die ("error: counting rows: ".mysql_error()); $i = 0; while ($i < mysql_num_fields ($sql)) { $row = mysql_fetch_field ($sql); $result.= '
  1. ' . $row->name . '
  2. '; $i++; } $result.= '
'; //----------- return $result; } function emptyHighscoreTable($login) { mysql_query("TRUNCATE TABLE `$login`") or die ("error: empty table: ".mysql_error()); } function showHighscoreCreationForm($count) { global $a,$gi,$rowcount; echo '
Here you can create the highscore table.
There are 4 default columns: name, score, client-id and timestamp.
If your highscore handles additional columns (i.e., if you created the highscore using "make_extended"), you must specify them here.
Please enter the number of additional columns you need and regenerate the form.

'; $i=0; for($i=0; $i < $count; $i++) { echo '
'; } echo '
'; } function columnOK($new_key,$keys) { $error=""; if($new_key->name == "") $error .= "Empty column name found. The highscore has been created with the remaining correct columns. If this is not your intention, delete the table and recreate it!"; foreach($keys as $key) { if($key->name == $new_key->name) { $error .= "Two columns with the same name found: '$key->name'. Maybe you didn't know that the highscore is case insensitive?
The highscore has been created with the remaining correct columns. If this is not your intention, delete the table and recreate it!"; break; } } switch ($new_key->name) { case "name": case "score": case "clientid": case "timestamp": $error .= "The specified column name '$new_key->name' is one of the default columns! The highscore has been created with the remaining correct columns. If this is not your intention, delete the table and recreate it!"; } if($error!="") { echo "
$error

"; return false; } else { return true; } } if(!$loggedin) echo "error: not logged in
\n"; else { /* what you have avaiable here is always: $login */ echo '
logout .:. delete account

'; if(isset($_REQUEST["delete"])) { deleteHighscoreTable($login); echo "Highscore table has been deleted!
You may now create a new one...

"; } if(isset($_REQUEST["empty"])) { emptyHighscoreTable($login); echo "Highscore table has been emptied!
"; } if(isset($_REQUEST["createhighscore"])) { if(highscoreTableExists($login)) die("SERIOUS ERROR: please contact the administrator!
\n"); $not_finished = true; $keys = array(); for($i=0;$not_finished;$i++) { if (isset($_REQUEST["col_name_$i"]) && isset($_REQUEST["col_type_$i"])) { $key->name = strtolower(ereg_replace("[^A-Za-z0-9]", "", $_REQUEST["col_name_$i"])); if($_REQUEST["col_type_$i"]==1) $key->type = "INT"; else $key->type = "VARCHAR(32)"; if(columnOK($key,$keys)) { array_push($keys,$key); } else { // stop processing input data... $not_finished=false; } } else { $not_finished=false; } } createHighscoreTable($login,$keys); } if(highscoreTableExists($login)) { echo highscoreTableStatus($login); echo "
Options:
delete highscore (the whole table will be deleted!)
empty highscore (all data is lost!)
\n"; } else { if(isset($_REQUEST["rowcount"])) $rowcount = $_REQUEST["rowcount"]; else $rowcount=0; showHighscoreCreationForm($rowcount); } } ?>