This topic is locked

After record added event

2/10/2007 4:05:15 AM
PHPRunner General questions
K
kenny_robb author

I am trying to add an event After Record Added. I want to write some stuff out to another table.
I have the following code but it gives me errors. Any help would be appreciated as I am still learning and do tend to get my syntax mixed up.
Basically I am selecting a number of distinct rows from a table and then using some of that information plus the information I have just added in the form to add a number of rows to another table.
[codebox]function AfterAdd()

{

//** Insert a record into another table ****

global $conn;

$strSQLQuery = "select distinct ID_game from elo_game";

$rsQuery = db_query($strSQLQuery,$conn);

$data=db_fetch_array($rsQuery);

if ( $data > 0 ){

for ($i=0; $i<$data; $i++){

$row = mysql_fetch_array($data);
$strSQLInsert = "insert into elo_values values (NULL,".$values["ID_player"].",".$row["ID_game"].",".$values["ID_country"].",1000)";

db_exec($strSQLInsert,$conn);
}

[/codebox]

J
Jane 2/12/2007

Kenny,
your event code is absolutely wrong.

function BeforeAdd(&$values)

{

//** Insert a record into another table ****

global $conn;

$strSQLQuery = "select distinct ID_game from elo_game";

$rsQuery = db_query($strSQLQuery,$conn);

while ($data=db_fetch_array($rsQuery))

{

$strSQLInsert = "insert into elo_values values (NULL,".$values["ID_player"].",".$values["ID_game"].",".$values["ID_country"].",1000)";

db_exec($strSQLInsert,$conn);

}

return true;

}

K
kenny_robb author 2/12/2007

I guessed that myself hence why I am trying to do it the another way.
See my other post which you are kindly helping me with....