ameriblog Posted August 25, 2007 Share Posted August 25, 2007 I am trying to get info from the database in a query and match it to a different table and then insert back into the main table. The issue I'm having is some of the fields are empty/don't match, so the variable $team1 or $team2 is empty and that causes an error in the insert query. That I tried to do, using intval() was that if the variable was empty that it automatically set $team1 or $team2 to zero. This isn't working, it isn't setting them to zero. Any tips would be greatly appreciated... $games_rs = $conn->Execute ( "SELECT * FROM ncaa_gm 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 ncaa_tm WHERE team_name = '" . $games_rs->Fields("team1_name") . "'" ) or die ( $conn->ErrorMsg() ); $team1 = $team1_rs->Fields("teamID"); $team1 = intval($team1); $team1_name = $team1_rs->Fields("team_name"); /* GET TEAM TWO INFORMATION */ $team2_rs = $conn->Execute ( "SELECT * FROM ncaa_tm WHERE team_name = '" . $games_rs->Fields("team2_name") . "'" ) or die ( $conn->ErrorMsg() ); $team2 = $team2_rs->Fields("teamID"); $team1 = intval($team2); $team2_name = $team2_rs->Fields("team_name"); /* START TEAM ONE CALCULATIONS */ $sql = "UPDATE ncaa_gm SET team1 = $team1, team2 = $team2 WHERE gameID = " . $games_rs->Fields("gameID") . ""; $add_rating_rs = $conn->Execute($sql) or die ( $conn->ErrorMsg() ); $games_rs->MoveNext(); } Link to comment https://forums.phpfreaks.com/topic/66677-set-variable-0-if-empty/ Share on other sites More sharing options...
MadTechie Posted August 25, 2007 Share Posted August 25, 2007 what about this if( ( is_string($var) && !empty($var) ) || (is_numeric ($var) && $var > 0) ) { //process $var } Link to comment https://forums.phpfreaks.com/topic/66677-set-variable-0-if-empty/#findComment-334174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.