Deleting from three tables at once

Discussion in 'PHP' started by zed420, Nov 30, 2008.

  1. #1
    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>"; 
      		} 
    	}
    }
    Code (markup):
    Thanks
    Zed
     
    zed420, Nov 30, 2008 IP
  2. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #2
    I think... you can't do this...
    you need 3 queries for 3 tables
     
    misbah, Nov 30, 2008 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    
    DELETE 
    	job_tb, blockBook, blockBook2
    	FROM
    		job_tb, blockBook, blockBook2
    	WHERE
    		job_tb.job_id = '$job_id' AND
    		blockBook.job_id = '$job_id' AND
    		blockBook2.job_id = '$job_id'
    
    Code (markup):
     
    joebert, Nov 30, 2008 IP