close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Deleteing related files?

Thread began 1/14/2010 8:57 am by Brad Lawryk | Last modified 4/01/2010 12:15 pm by Eric Mittman | 3657 views | 15 replies |

Brad Lawryk

Deleteing related files?

Suppose I have two tables ...

Table one

dog_id
dog_name

Table two

picture_id
picture_dog_id
Picture_file

Table one is a table of dogs and their names. Table two is a table of extra photos for each dog using the dog_id and picture_dog_id as the relationship between the two.

Is it possible on deletion of a dog from table one to delete the related images or even prevent deletion of the dog if there is matching images?

Sign in to reply to this post

Eric Mittman

Deleting the corresponding entries from the second table when you delete a dog from the first is definitely possible. You would just have an additional delete record server behavior and specify to delete from your second table where the deleted dog id matches the picture_dog_id. You can also use the delete files server behavior to delete the corresponding images as well.

To prevent the dog record from being deleted if there are entries in the other table you would have to do a custom check by having a recordset that selects all from the second table where the id matches for the first table. If there are any records in this recordset it would indicate that there are corresponding records. You could then redirect and display an error message.

Please post back with any specific questions that you have about any part of this.

Sign in to reply to this post

Brad Lawryk

Thanks Eric,

Good to know its possible ....

But how would I go about deleting however many related records there is? Sometimes there might be one record, sometimes none, sometimes maybe fifty?

This would be a very good and handy tutorial in your documentation.

Brad

Sign in to reply to this post

Eric Mittman

This is one of the nice things about using a delete server behavior for the records. If you filter the delete where the id matches the id of the record you are removing then it does not matter if you have one or a thousand records that have that id as the foreign key, they will all be deleted since they match the criteria.

Sign in to reply to this post

Brad Lawryk

Originally Said By: Eric Mittman
  This is one of the nice things about using a delete server behavior for the records. If you filter the delete where the id matches the id of the record you are removing then it does not matter if you have one or a thousand records that have that id as the foreign key, they will all be deleted since they match the criteria.  



Thanks Matt,

So you don't have to have any sort of repeat? I'll give it a try this afternoon.

Brad

Sign in to reply to this post

Eric Mittman

That is exactly rite, when deleting records from a table if you base the delete on a particular column matching a value wherever the column matches that value the record will be deleted.

Sign in to reply to this post

dinohorn397192

I'm currently doing the same thing and it works great. My question is, how would you go about deleting the image files associated with the photo table?

I added a delete behavior with Digital Assist Pro to do this and it works great. But it will only delete 1 image from the folder. How would I go about delete multiple files with that behavior?

I tried this, but it still would only delete 1 image from the folder.

<?php

do {
$WA_DeleteFileResult1 = false;
if(isset($_POST["DeleteGallery_x"])){


$WA_DeleteFileResult1 = WA_FileAssist_DeleteFile("../../pawpics_gallery/".$_SESSION['pawsid'] ."/", "".$row_photosRS['PhotoFilename'] ."");
}

} while ($row_photosRS = mysql_fetch_assoc($photosRS));
?>


Thanks

Sign in to reply to this post

Eric Mittman

It looks like you have the rite idea, looping over the delete for each file you would like to remove seems like the correct approach. Have you checked on your recordset after the page submits to check and see if you have all of the files contained within it? You should be able to add in some debug code to determine how many times the loop is iterating, this should give you a clue about why you are only seeing the one file delete.

Sign in to reply to this post

dinohorn397192

I'm doing the same loop on the page and outputting the recordset. e.g. image1.jpg image2.jpg, image3.jpg - so it looks like it's fine.

It will only delete one, it's like the loop isn't looping.

I pull the post statement out like below, still didn't work.

<?php
if(isset($_POST["DeleteGallery_x"])){
do {
$WA_DeleteFileResult1 = false;
$WA_DeleteFileResult1 = WA_FileAssist_DeleteFile("../../pawpics_gallery/".$_SESSION['pawsid'] ."/", "".$row_photosRS['PhotoFilename'] ."");
} while ($row_photosRS = mysql_fetch_assoc($photosRS));
}?>

Sign in to reply to this post

Eric Mittman

You should try setting a variable outside of the loop, then accumulate this value within the loop so that you can determine how many times the loop is occurring. You could set it up like so:

php:
$the_deleted_filenames = "";

do { 
$the_deleted_filenames .= $row_photosRS['PhotoFilename'] . ", ";
$WA_DeleteFileResult1 = false;
$WA_DeleteFileResult1 = WA_FileAssist_DeleteFile("../../pawpics_gallery/".$_SESSION['pawsid'] ."/", "".$row_photosRS['PhotoFilename'] ."");
} while ($row_photosRS = mysql_fetch_assoc($photosRS)); 
die("the deleted file names are: " . $the_deleted_filenames);



Give this a try to see the names of the files that are attempted to be deleted.

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...