I had a few simple questions and didn't want to have them on the board in short, separate threads.
I wrote a code that gets info from a games table in the database, matches up the teams listed for each of those games from the teams table and then inserts the teamID from the teams table in the games table in the appropriate field. So my teams table would say have two fields (teamID and team_name, where teamID is a pk, auto_increment, int, unsigned and team_name is a text field). My games table has 5 fields (gameID, team1, team1_name, team2, team2_name, where teamID is a pk, auto_increment, int, unsigned; team1 and team2 are INT fields, team1_name and team2_name are TEXT fields).
<?
require ( "conf.php" );
/* SELECT ALL GAMES */
$games_rs = $conn->Execute ( "SELECT * FROM game ORDER BY game_date DESC" ) or die ( $conn->ErrorMsg() );
/* START LOOP */
while ( ! $games_rs->EOF ) {
/* GET TEAM ONE INFORMATION */
$team1_rs = $conn->Execute ( "SELECT * FROM team WHERE team_name = '" . $games_rs->Fields("team1_name") . "' LIMIT 1" ) or die ( $conn->ErrorMsg() );
$team1 = $team1_rs->Fields("teamID");
$team1_name = $team1_rs->Fields("team_name");
/* GET TEAM TWO INFORMATION */
$team2_rs = $conn->Execute ( "SELECT * FROM team WHERE team_name = '" . $games_rs->Fields("team2_name") . "' LIMIT 1" ) or die ( $conn->ErrorMsg() );
$team2 = $team2_rs->Fields("teamID");
$team2_name = $team2_rs->Fields("team_name");
/* INSERT INFO */
$sql = "UPDATE game SET team1 = $team1, team2 = $team2 WHERE gameID = " . $games_rs->Fields("gameID") . "";
$add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() );
$games_rs->MoveNext(); }
That code works great unless there is no match for one of the teams and leaves $team1 or $team2 an empty variable. What I'd like for it to do, is if $team1 or $team2 is an empty variable is to enter a variable of 0.