function delete_chapter($id) { global $connection; // First, delete the options that are connected to the chapter delete_options($id); // Then delete rows from chapter_option that include this chapter delete_from_chapter_option($id); // Then nullify the child_chapter row in options table nullify_child_chapter($id); // Delete rows in story_chapter that include this chapter delete_from_story_chapter($id); // Then delete chapter $query = "DELETE FROM chapters WHERE id = {$id} LIMIT 1"; $result_set = mysql_query($query, $connection); confirm_query($result_set); }
$errors[] = mysql_error(); } else { // SUCCESS // Get a reference to the option_id just created $option_id = mysql_insert_id(); // Now create the option link in join table $query = "INSERT INTO chapter_option (chapter_id, option_id)\n\t\t\t\t\t\tVALUES (\t{$chapter_id}, {$option_id} )"; $result = mysql_query($query, $connection); if (!$result) { $errors[] = "problem with first insert. Story id: " . $chapter_id . " and option id: " . $option1ID . mysql_error(); } } } else { // There is an option 1, so UPDATE // OPTIONS TABLE UPDATE $option_id = $option['id']; if ($endpoint == 1) { // End the story here, so remove the options. // (Keep child chapters since we may still want to use them); delete_options($chapter_id); delete_from_chapter_option($chapter_id); } else { // It's not the end, so keep options $query = "UPDATE \t\toptions\n\t\t\t\t\t\tSET \t\tcontent\t\t= \t'{$content}'\n\t\t\t\t\t\tWHERE\t\tid\t=\t{$option_id}"; $result = mysql_query($query, $connection); if (!$result) { $errors[] = mysql_error(); } } } }