This topic is locked

Deleting records from related tables

1/5/2007 5:14:37 PM
PHPRunner General questions
D
Dale author

Im on my customer list page.

I want to delete my customer, BUT first I want to check to see if there are existing records in other tables. If there are, prompt to ask if you wish to delete them. If not, leave the record alone.
I have checked the forum for a similar situation and didnt find any info, unless I missed it.
I have three tables that are joined to the customer table with masterlinks.

When a user checks the row to delete, I do not want to delete the master record and then have the other records orphaned. IF the user selects Yes Delete them all, all the records should be deleted and then the customer record could be deleted.
I have it successfully checking to see if there are records, through the Before Delete event.
But I would like a confirm dialog to display before deleting or not.
Any previous posts or tips that will point me the way.

T
thesofa 1/6/2007

Hi

Happy New Year

the only refeernce I can find to alert boxes is here in this post

hth

D
Dale author 1/6/2007

A big Canadian Howdy to you thesofa.
Thanks for the pointer to the post. Looks like its just what I need. I will give it a go.
thanks

T
thesofa 1/7/2007

I am not sure how you get the alert to say "are you sure yoiu want to delete the record containing....... ....... ........|| Yes|No."

I would like to know how, if you decide to go that route plaese.

HTH

Sergey Kornilov admin 1/7/2007

Dale,
events are executed on the server side.

Alerts (yes/no popups) are created by javascript the client side. Combining server side and client side code in a single step is not possible.
Also, if several customers are selected to be deleted and some of them have data in related tables you need to ask one question per each customer. Don't look nice from end user point of view.
Probably you can delete records silently copying customers with child data to archive table.
Also you can have a custom field on the list page that displays a number of child records. This can help user to make a decision.

D
Dale author 1/7/2007

Thanks Sergey,
Very nice explanation. Not being an expert, I sometimes forget where the processing is happening.
I agree with all your points. I think what I will do is delete silently behind the scene but produce a stats list to show the user. ie. How many were deleted, how many subrecords and a list of records that were not deleted. Its never good to bother the user if you dont have to.
I hear what you are saying about the saving deletes to other tables. I thought I would wait and do it accross board when I have the initial application done. Also I was waiting to see the next version as you mentioned in the posts that a future release would have a change log built in. Depending on the data in the log, maybe I wont have to save deleted records in the database.
Thanks all.