Jump to content

Delete from multiple tables..


haku87

Recommended Posts

I have four tables.. t1,t2,t3,t4

t1 has a field called "id"

t2 has a field called "quizid"

t3 has a field called "quizid"

t4 has a field called "quizid"

 

I wan to delete all entries in these four tables which has a same id as $_POST[id].

The sql statement that i wrote cannot be use.. How to write the sql statement...

 

"DELETE tblquizmanagement, tblsaqmanagement, tblmcqmanagement,tbl_essay_ans FROM tblquizmanagement AS t1,tblsaqmanagement AS t2,tblmcqmanagement AS t3,tbl_essay_ans AS t4 WHERE t1.id ='".$_GET['quizid']."' AND t2.quizid = t1.quizid AND t3.quizid = t1.quizid AND t4.quizid = t1.quizid"

 

 

 

 

 

Link to comment
Share on other sites

Corrected...(Wouldn't let me edit)

<?php

$tables = array('t1','t2','t3','t4');
$id = $_POST[id];
$id_field = 'id';
$i = 1;

  foreach($tables as $t) {
    if($i > 1) $id_field = 'quizid';
    $DB->query("DELETE FROM `".$t."` WHERE `".$id_field."`='$id'");
    $i++;
  }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.