diff options
author | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-21 20:18:19 -0600 |
---|---|---|
committer | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-21 20:18:19 -0600 |
commit | efd7a7418ed94e26566ea97e23be9b00048e0c7f (patch) | |
tree | c945b4b1413197c5683db2b71ed3330d5036a549 | |
parent | ebf94d63edecf5263fe59c2ce3f08c7b0528e570 (diff) |
Start work on search page
-rw-r--r-- | all-posts.php | 28 | ||||
-rw-r--r-- | search.php | 61 | ||||
-rw-r--r-- | templates/header.php | 6 |
3 files changed, 64 insertions, 31 deletions
diff --git a/all-posts.php b/all-posts.php deleted file mode 100644 index fabeb3c..0000000 --- a/all-posts.php +++ /dev/null @@ -1,28 +0,0 @@ -<?php session_start()?> -<!DOCTYPE html> -<html> -<head> - <title>All posts - cflip.net forum</title> -</head> -<body style="width: 720px;margin: auto;"> - <?php include_once 'templates/header.php'; ?> - <h2>All Posts</h2> - <?php - include_once 'includes/db_inc.php'; - include_once 'includes/functions_display.php'; - - $sql = "SELECT post_id, post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id";; - $result = mysqli_query($dbc, $sql); - - if (!$result) { - die('Error trying to display posts: ' . mysqli_error($dbc)); - } - - if (mysqli_num_rows($result) == 0) { - echo 'This forum has no posts'; - } else { - display_posts($dbc, 1, $result); - } - ?> -</body> -</html>
\ No newline at end of file diff --git a/search.php b/search.php new file mode 100644 index 0000000..d90d0e6 --- /dev/null +++ b/search.php @@ -0,0 +1,61 @@ +<?php session_start()?> +<!DOCTYPE html> +<html> +<head> + <title>Search - cflip.net forum</title> +</head> +<body> + <?php include_once 'templates/header.php'; ?> + <h2>Search cflip.net forum</h2> + <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="get"> + Type: + <select name="type"> + <option value="thread">Thread</option> + <option value="post">Post</option> + <option value="user">User</option> + </select> + Sort By: + <select name="sort"> + <option value="lr">Last Reply</option> + <option value="cd">Creation Date</option> + <option value="rc">Reply Count</option> + </select> + With Name: + <input type="text" name="query"> + <input type="submit" value="Search!"> + </form> + <hr> + <?php + include_once 'includes/db_inc.php'; + include_once 'model/Thread.php'; + include_once 'model/Post.php'; + + if (!isset($_GET['type'])) { + echo 'Specify a type to search.'; + } else { + switch ($_GET['type']) { + case 'thread': + $threads = get_all_threads($dbc); + + foreach ($threads as $thread) { + echo '<p><b>' . $thread->subject . '</b> by <b>' . $thread->author->name . '</b></p>'; + } + break; + case 'post': + $posts = get_all_posts($dbc); + + foreach ($posts as $post) { + echo '<h4>From ' . $post->thread->subject . '</h4>'; + $post->display_content(); + } + break; + case 'user': + break; + default: + echo '<h3>Could not search: Invalid type!</h3>'; + break; + } + } + ?> +</body> +</html>
\ No newline at end of file diff --git a/templates/header.php b/templates/header.php index 526f63b..d7b8b78 100644 --- a/templates/header.php +++ b/templates/header.php @@ -1,14 +1,14 @@ <h1>cflip.net forum<sup style="font-size: small;">beta</sup></h1> [<a href="/forum/">Home</a>] -[<a href="/forum/all.php">All Threads</a>] -[<a href="/forum/all-posts.php">All Posts</a>] +[<a href="/forum/search.php?type=thread&sort=lr">All Threads</a>] +[<a href="/forum/search.php?type=post&sort=cd">All Posts</a>] [<a href="/forum/create_thread.php">Create a thread</a>] <span style="float:right;"> <?php if (isset($_SESSION['signed_in'])) { echo '[<a href="/forum/user/'. $_SESSION['user_name'] .'">' . $_SESSION['user_name'] . '\'s Profile</a>] [<a href="includes/signout_inc.php">Log out</a>]'; } else { - echo '<a class="nav_button" href="signin.php">Sign in</a> or <a class="nav_button" href="register.php">Register an account</a>'; + echo '[<a href="signin.php">Sign in</a>] or [<a href="register.php">Register an account</a>]'; } ?> </span>
\ No newline at end of file |