Click to See Complete Forum and Search --> : Delete from 4 tables?


chrisb
03-07-2007, 10:49 AM
Hello,

In my php page I've written I want to delete:

ANY records in my database where story_id=".$_POST["d$i"])

Now these could be in a table called stories, pictures, sounds, videos

So how do I do a delete on four tables? I tried a simple one with a join ie:


mysql_query("DELETE FROM a.stories, b.pictures FROM stories, pictures WHERE story_id=".$_POST["d$i"]);


But that does not work.

Can anyone help with this sql please

NightShift58
03-07-2007, 03:17 PM
You can delete FROM fields... and certainly not TWICE FROM fields and tables...DELETE FROM stories, picturesAlso, you'll have to find a way to define which rows in the second table should be deleted, unless both tables share the story_id field.

chrisb
03-08-2007, 02:32 AM
Hi,

I tried that (as I wondered if it could be as simple as that):


mysql_query("DELETE FROM stories, pictures, videos, sounds WHERE story_id=".$_POST["d$i"]);


And story_id is a field in all of those tables and it does not delete?

Any ideas?

Thanks

Chris

NightShift58
03-08-2007, 04:18 AM
<?php
$thisID = $_POST["d".$i];
mysql_query("
DELETE stories, pictures, videos, sounds
FROM stories, pictures, videos, sounds
WHERE stories.story_id = $thisID
AND pictures.story_id = $thisID
AND videos.story_id = $thisID
AND sounds.story_id = $thisID
");
?>