I wrote this code real quick, trying to get it to just at least update the games played and the games won or lost. For some reason it isn't inserting into the db.
My database structure is:
table TEAM
teamID (primary key)
team_name
team_w (default 0)
team_l (default 0)
team_gp (default 0)
table GAME
gameID (primary key)
game_home (fk, int)
game_home_score
game_away (fk, int)
game_away_score
game_date
<?
require ( "dbconnect.php" );
$games_rs = $conn->Execute ( "SELECT * FROM game ORDER BY game_date DESC" ) or die ( $conn->ErrorMsg() );
while ( ! $games_rs->EOF ) {
$team1_rs = $conn->Execute ( "SELECT * FROM team, game WHERE game_home = teamID AND gameID = " . $games_rs->Fields("gameID") . " ORDER BY game_date DESC" ) or die ( $conn->ErrorMsg() );
$team_rated = $team1_rs->Fields("game_home");
$team_win = $team1_rs->Fields("team_w");
$team_loss = $team1_rs->Fields("team_l");
$team_gp = $team1_rs->Fields("team_gp");
if ( $games_rs->Fields("game_home_score") > $games_rs->Fields("game_away_score") ) {
$new_gp = $team_gp + 1;
$new_win = $team_w + 1;
$new_loss = $team_l + 0;
}
if ( $games_rs->Fields("game_home_score") < $games_rs->Fields("game_away_score") ) {
$new_gp = $team_gp + 1;
$new_win = $team_w + 0;
$new_loss = $team_l + 1;
}
$sql = "UPDATE team SET team_gp = '$new_gp', team_w = '$new_win', team_l = '$new_loss' WHERE teamID = '$team_rated'";
$add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() );
$games_rs->MoveNext(); } ?>