I want to delete the entire content of the subject in the database when its id is deleted.
if(isset($_GET['subject_id'])){
$subject_id = $_GET['subject_id'];}
$deleteexams = mysql_query("SELECT * FROM exam_exams where exam_subject_id = '$subject_id'")or die(mysql_query());
while($ids = mysql_fetch_array($deleteexams)){
$selected = $ids['exam_id'];
}
$deletequestions = mysql_query("SELECT * FROM exam_questions where question_exam_id = '$selected'")or die(mysql_query());
while($ids2 = mysql_fetch_array($deletequestions)){
$selectedids = $ids2['question_id'];
}
$deleteanswers = mysql_query("SELECT * FROM exam_answers where answer_question_set_id = '$selectedids'")or die(mysql_query());
while($ids3 = mysql_fetch_array($deleteanswers)){
$selectedidsans = $ids3['answer_id'];
}
/// I want to delete all of the answers inside the questions of the exams in the subject
mysql_query("DELETE * FROM exam_answers where answer_id = '$selectedidsans'")or die(mysql_error());
/////i want to delete all the questions
mysql_query("DELETE * FROM exam_questions where answer_id = '$selectedids'")or die(mysql_error());
////this will work because this has the subject ids
mysql_query("DELETE * FROM exam_exams where exam_subject_id = '$subject_id'")or die(mysql_error());
/////and this too
mysql_query("DELETE * FROM exam_subjects where subject_id = '$subject_id'")or die(mysql_error());
My problem is how can I delete the answers and questions because it has no subject_id on its fields.