Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.