'Years School', 'years_regional' => 'Years Regional', 'years_national' => 'Years National', 'willing_chair' => 'Willing Chair'); foreach($qmap as $field=>$head) { $q = $pdo->prepare("SELECT id FROM questions WHERE db_heading='{$head}'"); $q->execute(); while($i = $q->fetch(PDO::FETCH_OBJ)) { $id = $i->id; /* Drop all answers for this question */ $stmt = $pdo->prepare("DELETE FROM question_answers WHERE questions_id='$id'"); $stmt->execute(); } /* Now dump the question itself */ $stmt = $pdo->prepare("DELETE FROM questions WHERE id='$id'"); $stmt->execute(); } }