A few notes: - You would add this code to update.php - The import pages would be accessed with update.php?import&div - You would have to configure the $uploadto path as the temporary path to store the CSV file - This code does not take seasons into account as it was written before seasons and master teams functionality was implemented - You'll have to analyze the code to see what order the fields should be in the CSV file In other words, this is a good framework to start with if you are familiar with PHP, but it might not take into account some of the database structure changes from later releases of the sports standings script. You should definitely test it on a separate install so that you don't mess up any existing teams until you know that the code is correct. --------------------------------- case 'import': if (isset($_POST['import'])) { // Which division are we importing to $divid = intval($_POST['divid']); // Which file we're working with $uploadto = $_POST['file_location']; // Which column represents dates] $date = intval($_POST['date']); $dates = array(); // Which column represents dates] $time = intval($_POST['time']); $times = array(); // Which column represents team 1 (home team) $team1 = intval($_POST['home']); $team1s = array(); // Which column represents team 2 (away team) $team2 = intval($_POST['away']); $team2s = array(); // Which column represents field $field = intval($_POST['field']); $fields = array(); // Make sure a different field has been mapped to each column $unique_check = array_unique(array($date, $time, $team1, $team2, $field)); if (count($unique_check) != 5) die ("You didn't assign unique columns. Try again."); // Put the lines from the file into an array $bigskedarray = file($uploadto); $i = 0; $separator = ","; while (list($i, $skedrow) = each($bigskedarray)) { $skedrow = trim($skedrow); $skedcell[$i] = explode("$separator", $skedrow); if ($i == 0) { $numcols = count($skedcell[0]); } else { // Add to the date array $dates[$i-1] = strtotime($skedcell[$i][$date]); // Add to the time array (using the date for the exact time) $times[$i-1] = strtotime($skedcell[$i][$date] . ' ' . $skedcell[$i][$time]); // Add to the Team 1 (home team) array $team1s[$i-1] = trim($skedcell[$i][$team1]); // Add to the Team 2 (away team) array $team2s[$i-1] = trim($skedcell[$i][$team2]); // Add to the fields array $fields[$i-1] = trim($skedcell[$i][$field]); } ++$i; } // Merge the team arrays $teams = array_merge($team1s, $team2s); // Generate a unique array of teams $unique_teams = array_values(array_unique($teams)); mysql_connect($sportsdb_host,$sportsdb_user,$sportsdb_pass); @mysql_select_db($sportsdb_db) or die( "Unable to select database"); // Insert the teams into MySQL foreach ($unique_teams as $unique_team) { $query = "INSERT INTO sportsdb_teams (teamname, teamdiv) VALUES ('$unique_team', $divid)"; mysql_query($query) or die ("Error in query: $query"); } print '

' . count($unique_teams) . ' teams imported

' . "\n"; // Insert the rows into the schedule for ($i = 0; $i < count($fields); ++$i) { $query = "INSERT INTO sportsdb_wins (winner, loser, windate, wintime, field) VALUES ('{$team1s[$i]}', '{$team2s[$i]}', {$dates[$i]}, {$times[$i]}, '{$fields[$i]}')"; mysql_query($query) or die ("Error in query: $query"); } print '

' . count($fields) . ' schedule entries imported

' . "\n"; // Replace all teams with numbers mysql_query("UPDATE sportsdb_wins, sportsdb_teams SET sportsdb_wins.winner = sportsdb_teams.teamid WHERE sportsdb_wins.winner = sportsdb_teams.teamname AND sportsdb_teams.teamdiv = $divid"); mysql_query("UPDATE sportsdb_wins, sportsdb_teams SET sportsdb_wins.loser = sportsdb_teams.teamid WHERE sportsdb_wins.loser = sportsdb_teams.teamname AND sportsdb_teams.teamdiv = $divid"); // Done! print '

Done

' . "\n"; print '

Import another division\'s schedule

' . "\n"; } if (isset($_POST['csv'])) { // Which division does this apply to $divid = intval($_POST['divid']); mysql_connect($sportsdb_host,$sportsdb_user,$sportsdb_pass); @mysql_select_db($sportsdb_db) or die( "Unable to select database"); $result = mysql_query("SELECT divname FROM sportsdb_divs WHERE divid = $divid"); $divname = mysql_result($result,0,'divname'); print "

Import schedule to $divname

\n"; // put the file somewhere $uploadto = "path/to/upload/" . basename($_FILES['schedule']['name']); move_uploaded_file($_FILES['schedule']['tmp_name'],$uploadto); // $separator = intval($_POST['separator']); // switch ($separator) { // default: $separator = ","; // } $separator = ","; $bigskedarray = file('../schedules/' . $_FILES['schedule']['name']); $separator = ","; $skedrow = trim($bigskedarray[0]); $skedcell[0] = explode("$separator", $skedrow); $numcols = count($skedcell[0]); print "

Header rows

\n"; for ($i = 0; $i < $numcols; ++$i) { $skedoptions .= '\n"; } $end_fields = array("date" => "Date", "time" => "Time", "home" => "Home team", "away" => "Away team", "field" => "Field"); print '
' . "\n"; foreach ($end_fields as $end_field => $end_name) { print "

$end_name:

\n"; } print '' . "\n"; print '' . "\n"; print '' . "\n"; print "
\n"; } else { if (isset($_GET['div'])) print '

Import CSV schedule

' . "\n"; ?>

Division:

Separator: // //

?>

Cancel

\n"; } break;