} // get the id of the TRAIN module $trainIdMod = module_utils::get_idMod('TRAIN', $mysqli); // Clear the TRAIN team $update = $mysqli->prepare("DELETE FROM modules_staff WHERE idMod = ?"); $update->bind_param('i', $trainIdMod); $update->execute(); $update->close(); // Get all the papers on the TRAIN team $result = $mysqli->prepare("SELECT properties.property_id FROM properties, properties_modules WHERE properties.property_id = properties_modules.property_id AND idMod = ?"); $result->bind_param('i', $trainIdMod); $result->execute(); $result->store_result(); $result->bind_result($paperID); while ($result->fetch()) { Paper_utils::remove_modules(array($trainIdMod => 'TRAIN'), $paperID, $mysqli); $q_result = $mysqli->prepare("SELECT question FROM papers WHERE paper=?"); $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