} else { //if class doesnt exist, add class to database $query = mysqli_query($con, "SELECT teacherid FROM login INNER JOIN teachers on login.userid=teachers.userid WHERE username='******'"); $result = mysqli_fetch_assoc($query); $teacherid = $result['teacherid']; $query = "INSERT INTO classlist (teacherid,classname) VALUES ('{$teacherid}','{$classname}')"; if (mysqli_query($con, $query)) { $_SESSION["error"] = 0; $_SESSION["addednewclass"] = True; header("Location:options.php"); } } } if (isset($_POST['removeclass'])) { $classname = $_POST["classnames"]; $classid = mysqli_fetch_Assoc(mysqli_query($con, "SELECT classid FROM classlist WHERE classname='" . $classname . "'"))['classid']; //no validation required due to drop down list, so just delete mysqli_query($con, "DELETE FROM classlist WHERE classname='" . $classname . "'"); mysqli_query($con, "DELETE FROM classstudent WHERE classid='" . $classid . "'"); $_SESSION["error"] = 0; $_SESSION["deleted"] = True; header("Location:options.php"); } if (isset($_POST['removeuser'])) { $username = $_POST["username"]; $classname = $_POST["classlist"]; //check username exists $query = mysqli_query($con, "SELECT * FROM login WHERE username='******'"); $checkusername = mysqli_num_rows($query); if ($checkusername != 1) { $_SESSION["error"] = 11;
// 通常、index.phpが表示された時 if ($page == '') { $page = 1; } // max関数:()内に指定した複数のデータから、一番大きい値を返す // ①表示する正しいページの数値(Min)を設定 $page = max($page, 1); // あいまい検索処理 if (isset($_GET['search_word']) && !empty($_GET['search_wrod'])) { $sql = sprintf('SELECT COUNT(*) AS cnt FROM `tweets` WHERE `tweet` LIKE "%%%s%%"', mysqli_real_escape_string($db, $_GET['search_word'])); } else { $sql = sprintf('SELECT COUNT(*) AS cnt FROM `tweets`'); } // ②必要なページ数を計算する $recordSet = mysqli_query($db, $sql) or die(mysqli_error($db)); $table = mysqli_fetch_Assoc($recordSet); // ceil()関数:切り上げ $maxPage = ceil($table['cnt'] / 5); // ③表示する正しいページ数の数値(Max)を設定 $page = min($page, $maxPage); // ④ページに表示する件数だけ取得 $start = ($page - 1) * 5; $start = max(0, $start); if (isset($_GET['search_word']) && !empty($_GET['search_word'])) { $sql = sprintf('SELECT m.nick_name, m.picture_path, t.* FROM `tweets` t, `members` m WHERE t.member_id = m.member_id AND t.tweet LIKE "%%%s%%" ORDER BY t.created DESC LIMIT %d, 5', mysqli_real_escape_string($db, $_GET['search_word']), $start); } else { // 投稿内容を取得する $sql = sprintf('SELECT m.nick_name, m.picture_path, t.* FROM `tweets` t, `members` m WHERE t.member_id = m.member_id ORDER BY t.created DESC LIMIT %d, 5', $start); } $tweets = mysqli_query($db, $sql) or die(mysqli_error($db)); if (isset($_REQUEST['res'])) {