This topic is locked

Check for child recs Before Delete

4/14/2011 12:43:57 AM
PHPRunner General questions
N
nti author

Requesting script for following action:
Check for child recs Before Delete and if child record exist, present user with custom message.
If user confirms delete, then delete record.
The Popup message if child recs exist would have confirm delete button or cancel button in case they wish to cancel delete.
I think I know? code will be placed at: EVENTS, List Page, Before record deleted.
I have tried many pieces of code with no success.
Now my arms are up and I am sinking into the deep darkness of php abyssal zone, hoping to be rescued by a beautiful...
Awh shucks, I best hit the couch and get some sleep. I hope someone gives up the secret to the treasure I seek above.
cheers, nti

J
Jane 4/14/2011

Hi,
unfortunately there is no easy way to check records in the detail table and then show 'confirm/cancel' popup.

You can check deleted records and delete all records (in the master and detail tables) in the List page: Before record deleted or List page: After record deleted events.

Here is a sample:

http://xlinesoft.com/phprunner/docs/before_deleting_a_record_check_if_related_records_exist.htm

N
nti author 4/14/2011



unfortunately there is no easy way to check records in the detail table and then show 'confirm/cancel' popup.


Thank you jane for reply. I utilze MySql with innoDB with delete cascade for child records.
Can you give me instructions for modifying the current popup which states: "Do you really want to delete these records? OK Cancel"
I hope each table has it's own current delete meassage popup? Thanks.

N
nti author 4/14/2011

Can I get additional insight for the script below?
// Parameters:

// where - string with WHERE clause pointing to record to be deleted.
global $dal;
$tblOrder = $dal->Table("OrderDetails"); // Do we modify this line like this? > $tblMY_MASTER_TABLE = $dal->Table("MY_CHILD_TABLE");
$rs = $tblOrder->Query("OrderID=".$deleted_values["OrderID"],""); // $rs = $tblMY_MASTER_TABLE->Query("MY_CHILD_TABLE_foreign key=".$deleted_values["MY_CHILD_TABLE_foreign key"],"");
$data = db_fetch_array($rs); // < what does this line do?
if($data)
return false; // < what does this line do?
else
return true; // < what does this line do?
// Many thank you's.

Admin 4/14/2011

An excerpt from http://xlinesoft.com/phprunner/docs/before_record_deleted.htm:

Return value

True - record will be deleted.
False - record would not be deleted.