condition check breakdown...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hc
Forum Newbie
Posts: 13
Joined: Wed Oct 25, 2006 2:00 pm

condition check breakdown...

Post by hc »

I have the following code, which seems to work fine. If I keep as is, I get the correct results, but if I uncomment the following lines

if($employer->InsertClientTeam($empid, $data))
{
$sHomeTeamClientAdded .= 'Team ' . $data['hometeam'] . ' added to client ' . $data['client'] .'</br>';
}

All of the sudden, my if statement

if($empid = $employer->ClientExists($data['client'], $data['sport_id']))

no longer evaluates to true, though it should because the records are actually in the DB. What about the $employer->InsertClientTeam($empid, $data) function is "resetting" the values? Can anyone help, I have spent all night on this. Thanks for taking a look

Code: Select all

	case "teams";
	{
		$employer = new Employer();
		$team = new Team();
		echo 'Here we will do lookup First the Client Name (EXACT MATCH). Then we add home and away teams if they do not already exist';
		echo '</br></br>';
		$formerclient = '';

		foreach ($_POST['chk'] as $name => $val)
		{

		$data['client'] = $_POST['client_' . $val];
		$data['hometeam'] = $_POST['home_' . $val];
		$data['awayteam'] = $_POST['away_' . $val];
		$data['sport_id'] = $_POST['sportid'];
		$data['imported_by']= 'oppExport';

			$client = $data['client'];
			if(isset($client))
			{

				if($client != $formerclient)
				{
					if($empid = $employer->ClientExists($data['client'], $data['sport_id']))
					{
						$sClientFound .= 'Client Found!' . $client . '-' . $data['sport_id'] . '</br>';
						if($team->GetTeamID($data['hometeam']))
						{
							$hometeamid = $team->GetTeamID($data['hometeam']);
							$sHomeTeamExists .= 'HomeTeam Exists-ID:' . $hometeamid . '-' . $data['hometeam'] . '</br>';
						}
						else
						{
							$data['name'] = $data['hometeam'];
							if($team->InsertTeam($data))
							{
								$hometeamid = $team->GetTeamID($data['hometeam']);
								$sHomeTeamAdded .= 'Team Added-New ID:' . $hometeamid . '-' . $data['hometeam'] . '</br>';
							}
							else
							{
								$sHomeTeamAdded .= 'Problem on INSERT:' . $data['home'] . '</br>';
							}
						}
						if(isset($empid) && isset($hometeamid))
						{
							$data['team_id'] = $hometeamid;
							$data['home'] = 'true';
							$data['away'] = 'false';
							//if($employer->InsertClientTeam($empid, $data))
							//{
								$sHomeTeamClientAdded .= 'Team ' . $data['hometeam'] . ' added to client ' . $data['client'] .'</br>';
							//}
						}
					}
					else
					{
						$sClientNotFound .= 'Client Not Found!' . $client . '-' . $data['sport_id'] . '</br>';
					}
					$formerclient = $client;
				}
			}
		}
		echo '<h3>Client Found</h3>' . $sClientFound;
		echo '<h3>Client Not Found</h3>' . $sClientNotFound;
		//echo '<h3>Team Exists</h3>' . $sHomeTeamExists;
		echo '<h3>Home Team Added</h3>' . $sHomeTeamAdded;
		//echo '<h3>Away Team Added</h3>' . $sAwayTeamAdded;
		echo '<h3>Team Client Added</h3>' . $sHomeTeamClientAdded;
		//echo '<h3>Away Team Client Added</h3>' . $sAwayTeamClientAdded;
		break;

Code: Select all

	/********************************************************
		void InsertClientTeam($emp_id, $data);

		Description:
			This will add a Team for $emp_id
	********************************************************/
	function InsertClientTeam($emp_id, $data)
	{
		$retval = false;
		if($this->EmployerExists($emp_id))
		{
			if(!$this->GetTeamLink($data['team_id']) )
			{
				$sqlstr = <<< SQL
					INSERT INTO
						businesses.employer_team (employer_id, team_id, home, away, imported_by)
					VALUES ($emp_id, $data[team_id], $data[home], $data[away], '$data[imported_by]')
SQL;
			}
			else if(!$this->TeamState($data))
			{
				$sqlstr = <<< SQL
					UPDATE
						businesses.employer_team
					SET
						status_id = 1,
						home = $data[home],
						away = $data[away]
					WHERE
						employer_id = $emp_id AND
						team_id = $data[team_id]
SQL;
			}

			if($this->Load($sqlstr))
			{
				//echo $sqlstr;
				$retval = true;
			}
		}
		//echo 'SQL IS: ' . $sqlstr;
		return $retval;
	} // AddTeam()
Post Reply