This topic is locked

How can I run this query as an AfterRecordDeleted event?

1/13/2007 10:52:32 PM
PHPRunner General questions
E
ERuiz author

I need to run this query, as an AfterRecordDeleted event on the List Page:

//Get total amount of old hours

$result = mysql_query("SELECT *, SUM(BlockTime) as oldhours FROM pirep WHERE IDPilot = ".$IDPilot." GROUP BY pilotname ORDER BY oldhours DESC LIMIT 1") or die(mysql_error());

$row = mysql_fetch_array( $result );

$oldhours = $row['oldhours'];
//Get total amount of transferred hours

$result = mysql_query("SELECT * FROM vb3_userfield WHERE userid = ".$IDPilot." ") or die(mysql_error());

$row = mysql_fetch_object( $result );

$transferredhours = $row['field13'];
//Determine if transferred hours is lower or higher than 100

if ($transferredhours >= 100) {

$transferredhours = 50;

}

else {

$transferredhours = 0;

}
//Add $oldhours and $transferredhours to get $totalhours

$totalhours = $oldhours + $transferredhours;
//Update the database with the final result of $totalhours

$queryupdate = mysql_query("UPDATE vb3_userfield SET field9 = ".$totalhours." WHERE userid = ".$IDPilot." ") or die(mysql_error());


Thanks for any help!
Regards,
ERuiz

J
Jane 1/15/2007

Hi,
I'm not sure that I understand you correctly.

If $IDPilot variable is stored ID of deleted record use Before record deleted event and $where variable:

function BeforeDelete($where)

{

$result = mysql_query("SELECT , SUM(BlockTime) as oldhours FROM pirep WHERE ". $where." GROUP BY pilotname ORDER BY oldhours DESC LIMIT 1") or die(mysql_error());

$row = mysql_fetch_array( $result );

$oldhours = $row['oldhours'];
//

global $conn,$strTableName;

$rs = db_query("select FieldName from ".$strTableName." where ".$where."",$conn);

$data = db_fetch_array($rs);

$IDPilot = $data["FieldName"];
//Get total amount of transferred hours

$result = mysql_query("SELECT
FROM vb3_userfield WHERE userid = ".$IDPilot." ") or die(mysql_error());

$row = mysql_fetch_object( $result );

$transferredhours = $row['field13'];
//Determine if transferred hours is lower or higher than 100

if ($transferredhours >= 100) {

$transferredhours = 50;

}

else {

$transferredhours = 0;

}
//Add $oldhours and $transferredhours to get $totalhours

$totalhours = $oldhours + $transferredhours;
//Update the database with the final result of $totalhours

$queryupdate = mysql_query("UPDATE vb3_userfield SET field9 = ".$totalhours." WHERE userid = ".$IDPilot." ") or die(mysql_error());

return true;

}



where Fieldname is your actual field name where IDPilot is stored.