$q_result->bind_param('i', $paperID); $q_result->execute(); $q_result->store_result(); $q_result->bind_result($questionID); while ($q_result->fetch()) { // Check the question isn't used on any other papers $check = $mysqli->prepare("SELECT question FROM papers WHERE question=?"); $check->bind_param('i', $questionID); $check->execute(); $check->store_result(); $check->bind_result($questionID); $check->fetch(); if ($check->num_rows == 1) { //delete the question its only on 1 training paper QuestionUtils::delete_question($questionID, $mysqli); } else { //remove from the TRAIN module dont delete ;-) its used elsewhere QuestionUtils::remove_modules(array($trainIdMod => 'TRAIN'), $questionID, $mysqli); } $check->close(); } $q_result->close(); //delete the paper if it is not on any other modules $tmp_paper_modules = Paper_utils::get_modules($paperID, $mysqli); if (count($tmp_paper_modules) == 0) { Paper_utils::delete_paper($paperID, $mysqli); } } $result->close(); $mysqli->close(); header("location: index.php");