Forum Moderators: coopster

Message Too Old, No Replies

Deleting from three tables at once

         

zed420

8:18 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



Hi All
Can someone tell me if this is possible or do I need to wake up. I'm trying to delete some records from three different tables at once via check boxes, tabls don't have any join. This doesn't give me any error but not working either. It does work with ONE table at a time thou. some help will be greatley appreciated.
if($_POST['delete']) {
foreach($_POST as $job_id) {
mysql_query("DELETE FROM job_tb,blockBook,blockBook2
WHERE job_tb.job_id='$job_id' OR
blockBook.job_id= '$job_id' OR
blockBook2.job_id= '$job_id'");
if (mysql_affected_rows() > 0) {
print "<font color=red size=2>Job No. = $Job_id has been deleted</font><p>";
}
}
}

Thanks
Zed

Pico_Train

10:47 am on Dec 1, 2008 (gmt 0)

10+ Year Member



Do it one table at a time, I definitely would. Easier to debug later on too. Much simpler.

henry0

12:27 pm on Dec 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'll too do it one at a time
but I will also, again one at a time, first load the deleted data in a temp table, check if it was really deleted, same for # 2 and #3 , to be sure you are not creating havoc, if one fell then reload the data from the temp,
send yourself an error message etc...

to create a temp table
mysql> CREATE TEMPORARY TABLE whatever (
etc….

Dropping the temp
by default MySQL will delete it when the connection is closed
but if you need to drop it earlier use the drop command

SarK0Y

9:44 pm on Dec 4, 2008 (gmt 0)

10+ Year Member



if tables have relations with each other, use transactions and operation will be atomic.