This topic is locked

Auto add another record into a table dependant upon an entered value

8/22/2006 8:47:58 AM
PHPRunner General questions
A
Alan4573 author

Hi,
I am putting together a project for a football cup competion.

In my database I have a table which logs details of the games.
I have (amongst others) the following fields:
Home (Home Team)

Away (Away Team)

HomeScore (Home Goals)

AwayScore (Away Goals)

Winners (Winning Team)
What I want to achieve is that after adding or editing the record, I want the Winners field to be auto populated with the Team (Home or Away field) that has the highest number of goals.
Eg, if the HomeScore field = 3 and the AwayScore field = 1 then the contents of the Home field would be inserted into the Winners field.

Likewise, if the AwayScore field is higher, then the contents of the Away field should be inserted into the Winners field.
I imagine I would use events to achieve this, but I have no idea how - can anyone help.
Thanks in advance.
Alan

J
Jane 8/22/2006

Alan,
you can do it using Before record added or Before record updated event.

Here is a sample code for the BeforeAdd event:

function BeforeAdd(&$values)

{

if ($values["HomeScore"]>$values["AwayScore"])

$values["Winners"] = $values["Home"];

else

$values["Winners"] = $values["Away"];
return true;

}



And then uncheck Winners field from ADD page on the Choose fields tab (step 6) in the PHPRunner.

A
Alan4573 author 8/22/2006

Jane,
Superb support - thanks a million.
Alan