From c84215091e914c81937c3aad2f1fd1775f556aa6 Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Sun, 21 Mar 2021 17:37:13 -0600 Subject: Changes from procedural to OOP --- category.php | 38 ++++++++------------------------------ index.php | 45 ++++++++++++++++++++++----------------------- thread.php | 17 ++++------------- user.php | 28 +++++++--------------------- 4 files changed, 41 insertions(+), 87 deletions(-) diff --git a/category.php b/category.php index e559f22..a71029e 100644 --- a/category.php +++ b/category.php @@ -16,7 +16,7 @@ if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) { <?php echo $current->name; ?> - cflip.net forum - +

name; ?>

description; ?>

@@ -28,36 +28,14 @@ if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) { Latest Post get_threads($dbc); - $threads = current->get_threads(); - for each thread { - $thread->get_latest_post(); - } - - $sql = " - SELECT thread_id, thread_subject, thread_date_created, thread_date_lastpost, thread_category, thread_author, user_id, user_name - FROM threads - LEFT JOIN users - ON thread_author = user_id - WHERE thread_category = " . $_GET['id']; - - $result = mysqli_query($dbc, $sql); - - if (!$result) { - die('Error trying to display posts: ' . mysqli_error($dbc)); - } - - if (mysqli_num_rows($result) == 0) { - echo 'No categories found!'; - } else { - while ($row = mysqli_fetch_assoc($result)) { - echo ''; - echo '' . $row['thread_subject'] . '
'; - echo 'by ' . $row['user_name'] . ' on ' . date('M d, Y', strtotime($row['thread_date_created'])) . ''; - echo '' . date('M d, Y', strtotime($row['thread_date_lastpost'])) . ''; - echo ''; - } + foreach ($threads as $thread) { + echo ''; + echo '' . $thread->subject . '
'; + echo 'by ' . $thread->author->name . ' on ' . date('M d, Y', strtotime($thread->date_created)) . ''; + echo '' . date('M d, Y', strtotime($thread->date_lastpost)) . ''; + echo ''; } ?> diff --git a/index.php b/index.php index 900918b..6c1c0c9 100644 --- a/index.php +++ b/index.php @@ -4,7 +4,7 @@ cflip.net forum - +

Welcome to the cflip.net forum!

@@ -24,35 +24,34 @@ id == $b->id) { + return 0; + } + return ($a->id < $b->id) ? -1 : 1; } - if (mysqli_num_rows($result) == 0) { - echo 'No categories found!'; - } else { - while ($row = mysqli_fetch_assoc($result)) { - echo ' - - ' . $row['cat_name'] . ' -
- ' . $row['cat_description'] . ' - - ' . $row['cat_thread_count'] . ' - ' . $row['cat_post_count'] . ' - my supercool thread
by cflip, 3 days ago - -'; - } + $categories = get_all_categories($dbc); + usort($categories, "cmp"); + + foreach ($categories as $category) { + echo ''; + echo ''; + echo '' . $category->name . ''; + echo '
' . $category->description; + echo ''; + echo '' . $category->thread_count . ''; + echo '' . $category->post_count . ''; + echo 'my supercool thread
by cflip, 3 days ago'; + echo ''; } ?>

More from the forum

- +
diff --git a/thread.php b/thread.php index 9c43217..3a65114 100644 --- a/thread.php +++ b/thread.php @@ -19,24 +19,15 @@ if (!isset($_GET['id']) || !filter_var($_GET['id'], FILTER_VALIDATE_INT)) {

subject; ?>

- created by user->name'; ?> + created by author->name; ?> in category->name; ?>3 days ago
get_posts($dbc); - $sql = "SELECT post_id, post_content, post_date, post_author, user_id, user_name FROM posts LEFT JOIN users ON post_author = user_id WHERE post_thread = " . mysqli_real_escape_string($dbc, $_GET['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 thread has no posts
'; - } else { - display_posts($dbc, $_GET['id'], $result); + foreach ($posts as $post) { + $post->display_content(); } ?> diff --git a/user.php b/user.php index a5e1d16..8685fcf 100644 --- a/user.php +++ b/user.php @@ -1,38 +1,24 @@ get_by_name($_GET['name'], $dbc); } ?> - <?php echo $user_name; ?>'s Profile - cflip.net forum + <?php echo $current->name; ?>'s Profile - cflip.net forum - + -

- member since +

name; ?>

+ member since date)); ?> \ No newline at end of file -- cgit v1.2.3
Recent Posts Recent Threads