close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Delete multiple records and files?

Thread began 6/26/2012 8:20 am by MikeH | Last modified 8/16/2013 4:50 pm by Jason Byrnes | 1995 views | 21 replies |

MikeH

Delete multiple records and files?

Hi
Im am trying to work out how to use DB to solve this:

Two database tables:

TableA:
ID
description

TableB:
ID
Thelink (Same as TableA ID)
Imagename (associated image is on server)

If I want to delete TableA record 50 how would I use DB to delete the record from TableA and ALL assocated records from TableB and finally the image files named in each TableB record there could be various amounts linked to a record in TableA.

Im assuming this is possible using Db just not sure how to start.

Thanks

Mike

Sign in to reply to this post

Ian S

This post has been deleted.

Jason ByrnesWebAssist

the record deletion is the easy part.

your delete page will have a hidden element that is used to pass the ID of the record to delete, in your example, the value of the hidden element would be 50:

php:
<input type="hidden" name="deleteID" id="deleteID" value="50" />



you would add two delete record behaviors.

the first for tableA, set the key column to ID and the value to use the deleteID hidden form element.

in the second delete behavior for tableB, set the key column to Thelink and for the value use the deleteID hidden element again.


the tougher part will be deleting the files. This will take a little bit of hand coding, but not to much.

First create a recordset to query tableB and filter the Thelink column using the deleteID form element.

This will return a recordset that contains all of the file names to delete.

Then add the delete file behavior, set the trigger to recordset recordsetName is not empty

Set the Delete folder to the folder that contains the images to delete.

for the file name, click the lightning bolt icon and select the Imagename column

the delete file code on the page will look similar to this:

php:
<?php

$WA_DeleteFileResult1 
false;
if((
$totalRows_recordsetName == 0)){
    
$WA_DeleteFileResult1 WA_FileAssist_DeleteFile("imageFolder/""".$row_recordsetName['Imagename']  ."");
}
?>



We need to add a loop around that code to loop through the recordset:

php:
<?php do { ?>

<?php
$WA_DeleteFileResult1 
false;
if((
$totalRows_recordsetName == 0)){
    
$WA_DeleteFileResult1 WA_FileAssist_DeleteFile("imageFolder/""".$row_recordsetName['Imagename']  ."");
}
?>
<?php 
} while ($row_recordsetName mysql_fetch_assoc($recordsetName)); ?>
Sign in to reply to this post

MikeH

Thanks Jason
How would I get the file delation to start only when the form "delete" button is pressed?

Thanks

Mike

Sign in to reply to this post

Jason ByrnesWebAssist

My solution already tries to delete only if the form is posted.

since the file delation relies on the recordset not being empty, and the record is filtered on the form variable.

The only way the recordset is not empty is if the delete button is pressed.

Sign in to reply to this post

MikeH

hi Jason
Thanks I couldnt get it to work. It did not appear to do anything.

If you are ever bored the files attached.

You are busy enough so do not worry.

Thanks

Mike

Attached Files
pgn_delete_car.zip
Sign in to reply to this post

Jason ByrnesWebAssist

everything looks correct.

I suspect that if you where to refresh the page, it would show that the record where deleted.

There isn't a redirect to another page, that is why it appears not to do anything.

on the server behaviors panel, click the plus button and select WebAssist -> Utilities -> Server redirect.

Set the trigger to Current page Submit and select the results page.

Sign in to reply to this post

MikeH

Hi Jason
I added that and it does redirect but even though I have told it to redirect to the correct page it gives a 403 forbidden and has tried to go where I never told it to :)

Also no deletions took place neither records or files.

A little annoying considering you have taken the time out to help. Does certainly feel like its wasting your time. Possible time for a multiple file delete beahviour from WA :)

Mike

Sign in to reply to this post

Jason ByrnesWebAssist

send a current copy of the page please, the redirect is probably happening before the delete.

Sign in to reply to this post

MikeH

Thanks Jason

Its attached... for some reason its trying to go to a plugins directory but that wasnt where the resirect is set to.

Mike

Attached Files
pgn_delete_car.zip
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...