/** * Return the number of rows in a table * * @return int number of rows */ public function getRowCount() { switch ($this->filter) { case "all-stories": $query = "SELECT COUNT(*) FROM stories"; break; case "all-chapters": if (isset($_GET['chapter']) && is_numeric($_GET['chapter'])) { $chapterID = intval($_GET['chapter']); $story = get_story_by_chapter($chapterID); //$chapter_set = get_chapters_in_story($story['id']); } $query = "SELECT COUNT(*) "; $query .= "FROM chapters "; $query .= "LEFT JOIN story_chapter "; $query .= "ON chapters.id = story_chapter.chapter_id "; $query .= "LEFT JOIN stories "; $query .= "ON story_chapter.story_id = stories.id "; $query .= "WHERE stories.id= " . $story['id']; $result_set = mysql_query($query, $connection); confirm_query($result_set); return $result_set; break; case "user-stories": if (isset($_SESSION['user_id'])) { $this->userID = $_SESSION['user_id']; $query = "SELECT COUNT(*) FROM stories \n\t\t\t\t\t\t\t\t\t\tLEFT JOIN stories_users su \n\t\t\t\t\t\t\t\t\t\tON stories.id = su.story_id \n\t\t\t\t\t\t\t\t\t\tLEFT JOIN users u \n\t\t\t\t\t\t\t\t\t\tON u.id = su.user_id \n\t\t\t\t\t\t\t\t\t\tWHERE u.id = {$this->userID}"; } break; default: return; } $result = mysql_query($query, $this->connection) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); return $r[0]; }
<?php require_once "helper-functions/session.php"; require_once "helper-functions/functions.php"; require_once "helper-functions/delete_functions.php"; confirm_logged_in(); // lives on session.php page require_once "helper-functions/connection.php"; include_once "helper-functions/form_functions.php"; /* Get references to the selected story and to its options --> $select_story comes from find_selected_story() --> $options array comes from get_just_options($id) --> */ if ($select_chapter = find_selected_chapter()) { $story = get_story_by_chapter($select_chapter['id']); set_chapter_in_session($select_chapter['id']); $options = get_just_options($select_chapter['id']); } else { redirect_to('404.php'); } if (!empty($_GET['parent_id'])) { $parent_id = intval($_GET['parent_id']); } if (isset($_POST['submit'])) { // Get endpoint radio button, since required fields vary depending on this number if (isset($_POST['endpoint'])) { $endpoint = 0; } else { $endpoint = 1; } // Do form validation // Form validation
} else { $message = "There were " . count($errors) . " errors in the form."; } } } else { // Form has not been submitted, so set form variable(s) to empty strings. // That is, the user will be seeing this page for first time, so we show them the empty form $options = array(); // Nothing to set... } include "includes/header.php"; if (!empty($_GET['story_id'])) { $story = get_story_by_id($_GET['story_id']); } else { if (!empty($_GET['parent_id'])) { $story = get_story_by_chapter($_GET['parent_id']); } else { $story = get_story_by_id($_SESSION['story_id']); } } $first_chapter; if ($variables["parent_option_id"] == 0) { $first_chapter = true; $message = "Your story has been saved! Get started..."; } else { $first_chapter = false; } ?> <!-- TITLE --> <h2 class="page-title alt"> Create chapter for<span> <?php
// ***************************************************************************** // Select existing chapter.php. Lists all chapters in a story with links to use as an option. // The idea is to help a writer reuse chapters rather than create new ones. // ***************************************************************************** ?> <h2 class="page-title">Use Existing</h2> <div id="chapter-block"> <p class="description"> Select one of the existing chapters instead of creating a new one. The effect will be to have loops within your story, where a reader might end up back in a chapter they've already read... </p> </div> <?php if (isset($_GET['chapter']) && is_numeric($_GET['chapter'])) { $chapterID = intval($_GET['chapter']); $story = get_story_by_chapter($chapterID); $chapter_set = get_chapters_in_story($story['id']); } if (isset($_GET['option']) && is_numeric($_GET['option'])) { $option_id = intval($_GET['option']); } global $connection; $pager = new Pager($connection, "all-chapters"); $result = $pager->getResult(); // Use $story_set data // Loop through data to create list of stories if (isset($chapter_set)) { while ($chapter = mysql_fetch_array($chapter_set)) { ?> <div class="body"> <?php