Dan Becker's Games Site

Validate Score PlayIDs

Purpose: Validate Scores table.Ensure that all playids in the Scores table exist in the Plays

\n"; $commandDelim = "=,"; $command = strtok( $update, $commandDelim ); if (0 == strcmp( $command, "update" )) { $scoreid = strtok( $commandDelim ); $playerid = strtok( $commandDelim ); if (( false != $scoreid ) && ( false != $playerid )) { $sql = "UPDATE $scoreTable SET playerid = $playerid WHERE ( scoreid = $scoreid )"; $sqlResults = sqlQuery( $sql, false ); } else { echo "Error: Garbled score or player id command=$command, scoreid=\"$scoreid\", playerid=\"$playerid\".
\n"; } } else if (0 == strcmp( $command, "insert" )) { $newName = strtok( $commandDelim ); if (( false != $newName ) && ( strlen( $newName ) > 0 )) { $sql = "INSERT INTO $playerNamesTable ( name ) VALUES ( \"$newName\" )"; $sqlResults = sqlQuery( $sql, false ); } else { echo "Error: Garbled player name for command=$command, name=\"$newName\".
\n"; } } else if (0 == strcmp( $command, "delete" )) { $scoreid = strtok( $commandDelim ); if (( false != $scoreid ) && ( strlen( $scoreid ) > 0 )) { $sql = "DELETE FROM $scoreTable WHERE ( scoreid = $scoreid )"; $sqlResults = sqlQuery( $sql, false ); } else { echo "Error: Garbled scoreid for command=$command, scoreid=\"$scoreid\".
\n"; } } else if (0 == strcmp( $command, "deleteall" )) { $name = strtok( $commandDelim ); if (( false != $name ) && ( strlen( $name ) > 0 )) { $sql = "DELETE FROM $scoreTable WHERE ( player = '$name' )"; $sqlResults = sqlQuery( $sql, false ); } else { echo "Error: Garbled player name for command=$command, name=\"$name\".
\n"; } } else if (0 == strcmp( $command, "deleteScore" )) { $scoreid = strtok( $commandDelim ); if (( false != $scoreid ) && ( strlen( $scoreid ) > 0 )) { $sql = "DELETE FROM $scoreTable WHERE ( scoreid = $scoreid )"; $sqlResults = sqlQuery( $sql, false ); } else { echo "Error: Garbled scoreid for command=$command, scoreid=\"$scoreid\".
\n"; } } else if (0 == strcmp( $command, "deleteScorePlay" )) { $playid = strtok( $commandDelim ); if (( false != $playid ) && ( strlen( $playid ) > 0 )) { $sql = "DELETE FROM $scoreTable WHERE ( playid = $playid )"; $sqlResults = sqlQuery( $sql, false ); } else { echo "Error: Garbled playid for command=$command, playid=\"$playid\".
\n"; } } else { echo "Error: Unknown command \"$command\".
\n"; }}// Do a check that all play ids in Scores exists in Plays.// Cannot do sub selects.// $sql = "SELECT scoreid, $scoreTable.playid, playerid, player, points// FROM $scoreTable// WHERE $playerid NOT IN// ( SELECT $playerNamesTable.playerid FROM $playerNamesTable )";$sql = "SELECT scoreid, $scoreTable.playid AS BadPlay, playerids, points FROM $scoreTable LEFT JOIN $playTable ON $scoreTable.playid=$playTable.playid WHERE $playTable.playid IS NULL";$sqlResults = sqlQuery( $sql, false );if ( 0 < mysql_num_rows( $sqlResults ) ) { echo "

Warning: The following $scoreTable play ids do not exist in $playTable.
\n"; // Show first 10 tables with this problem showResults( $sqlResults, true, 0, 10 ); // Rewind results to first item. mysql_data_seek( $sqlResults, 0 ); // Turn result into array. Use MYSQL_ASSOC, MYSQL_NUM, or MYSQL_BOTH to select keying. while ( $data = mysql_fetch_array( $sqlResults, MYSQL_ASSOC )) { $scoreid = $data[ "scoreid" ]; $playid = $data[ "BadPlay" ]; echo "
Did not find $playTable playid=$playid.\n"; // Output form to give user a choice. echo "

\n"; echo "\n"; echo "\n"; // Add the option of deleting all of this name from the database echo "\n"; echo "\n"; echo "\n"; echo "
Score table scoreid=\"$scoreid\"
Remove this Score playid
Remove this Score scoreid
\n"; echo "
\n"; } // while} else echo "

All $scoreTable playids exist in $playTable.
\n";?>

User menu |Admin menu