Multi Delete Query Problem
Posted: Fri Jun 18, 2010 3:47 pm
Hi,
I am trying to delete multiple data from my database at ones. I did this query but I am having a problem. The problem is that all genres, directors, comments, favorites and ratings have been deleted. However only the movie that have the ID from the $_GET['id'] has been deleted.
I want that all the records in the movies, genres, directors, comments, favorites and ratings tables that has a relation with the movie that has been deleted will be deleted will be deleted too.
Any Help please?
I am trying to delete multiple data from my database at ones. I did this query but I am having a problem. The problem is that all genres, directors, comments, favorites and ratings have been deleted. However only the movie that have the ID from the $_GET['id'] has been deleted.
I want that all the records in the movies, genres, directors, comments, favorites and ratings tables that has a relation with the movie that has been deleted will be deleted will be deleted too.
Code: Select all
$delete = "DELETE movies, genres, directors, comments, favorites, ratings FROM movies, genres, directors, comments, favorites, ratings WHERE movies.MovieID = '" . $_GET['id'] . "' AND (movies.MovieID = genres.MovieID OR movies.MovieID = directors.MovieID OR movies.MovieID = comments.MovieID OR movies.MovieID = favorites.MovieID OR movies.MovieID = ratings.MovieID)";
mysql_query($delete) or die(mysql_error());