Page 1 of 1

last question today! promise!

Posted: Mon Oct 30, 2006 4:11 pm
by hc
I have the following function that expects and array called $data. How do I get the following form posts into the array that will be used when I call this function? I did not write these functions. Though I have a programming background, its not PHP, so any help is appreciated. I promise you wont have to explain it more than once! :wink:

$found = false;
$client = $_POST['client_' . $val];
$home = $_POST['home_' . $val];
$away = $_POST['away_' . $val];
$sport_id = $_POST['sportid'];
$teamname = '';
$team_id = -1;
$true = true;
$false = false;

Code: Select all

		/********************************************************
		void AddTeam($data);

		Description:
			This will add a Team for $this->employer_id
	********************************************************/
	function AddTeam($data)
	{
		$retval = false;
		if($this->EmployerExists($this->employer_id))
		{
			if(!$this->GetTeamLink($data['team_id']) )
			{
				$sqlstr = <<< SQL
					INSERT INTO
						businesses.employer_team (employer_id, team_id, home, away)
					VALUES ($this->employer_id, $data[team_id], $data[home], $data[away])
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 = $this->employer_id AND
						team_id = $data[team_id]
SQL;
			}

			if($this->Load($sqlstr))
			{
				$retval = true;
			}
		}
		return $retval;
	} // AddTeam()

Posted: Mon Oct 30, 2006 4:17 pm
by Zoxive
Instead of making them all like....

Code: Select all

$found = false;
$client = $_POST['client_' . $val];
$home = $_POST['home_' . $val];
$away = $_POST['away_' . $val];
$sport_id = $_POST['sportid'];
$teamname = '';
$team_id = -1;
$true = true;
$false = false;
Make them like

Code: Select all

$array['found']= false;
$array['client'] = $_POST['client_' . $val];
$array['home']= $_POST['home_' . $val];
$array['away'] = $_POST['away_' . $val];
$array['sport_id']= $_POST['sportid'];
$array['teamname'] = '';
$array['team_id'] = -1;
$array['true'] = true;
$array['false'] = false;

// To call it
AddTeam($array); 

// You can name array to anything you want.
-NSF

Thanks, appreciate it..

Posted: Mon Oct 30, 2006 4:20 pm
by hc
thank you

Posted: Mon Oct 30, 2006 6:29 pm
by RobertGonzalez
If you are asking about getting information from $_POST, it is a superglobal and available to you in the global scope of the app.