From faae3f3906575b9c72d628a5e48d03f943c794fc Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Sat, 17 Apr 2021 17:36:18 -0600 Subject: Automatically sort threads without PHP comparisons --- model/Category.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'model/Category.php') diff --git a/model/Category.php b/model/Category.php index 1b699fb..b7c46d9 100644 --- a/model/Category.php +++ b/model/Category.php @@ -34,7 +34,7 @@ class Category { } function get_threads($dbc) { - $sql = "SELECT thread_id FROM threads WHERE thread_category = " . $this->id . " ORDER BY thread_date_lastpost"; + $sql = "SELECT thread_id FROM threads WHERE thread_category = " . $this->id . " ORDER BY thread_date_lastpost DESC"; $result = mysqli_query($dbc, $sql); if (!$result) { @@ -80,7 +80,7 @@ class Category { } function get_all_categories($dbc) { - $sql = "SELECT cat_id FROM categories"; + $sql = "SELECT cat_id FROM categories ORDER BY cat_id ASC;"; $result = mysqli_query($dbc, $sql); if (!$result) { -- cgit v1.2.3 From 6c9369ad85f2fb3dc61234b54db7e7079cdc0c4e Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Fri, 23 Apr 2021 18:43:12 -0600 Subject: Refactoring part 1 --- model/Category.php | 103 ----------------------------------------------------- 1 file changed, 103 deletions(-) delete mode 100644 model/Category.php (limited to 'model/Category.php') diff --git a/model/Category.php b/model/Category.php deleted file mode 100644 index b7c46d9..0000000 --- a/model/Category.php +++ /dev/null @@ -1,103 +0,0 @@ -id = $id; - $this->name = $row['cat_name']; - $this->description = $row['cat_description']; - $this->thread_count = $row['cat_thread_count']; - $this->post_count = $row['cat_post_count']; - } - } - - mysqli_free_result($result); - return 1; - } - - function get_threads($dbc) { - $sql = "SELECT thread_id FROM threads WHERE thread_category = " . $this->id . " ORDER BY thread_date_lastpost DESC"; - $result = mysqli_query($dbc, $sql); - - if (!$result) { - echo 'Could not get threads from category: ' . mysqli_error($dbc); - } - - $threads = array(); - - if (mysqli_num_rows($result) == 0) { - } else { - while ($row = mysqli_fetch_assoc($result)) { - $thread = new Thread(); - $thread->get_from_database($row['thread_id'], $dbc); - array_push($threads, $thread); - } - } - - mysqli_free_result($result); - return $threads; - } - - function get_latest_thread($dbc) { - $sql = "SELECT thread_id FROM threads WHERE thread_category = " . $this->id . " ORDER BY thread_date_lastpost DESC LIMIT 1"; - $result = mysqli_query($dbc, $sql); - - if (!$result) { - echo 'Could not get thread from category: ' . mysqli_error($dbc); - } - - $thread = null; - - if (mysqli_num_rows($result) == 0) { - } else { - while ($row = mysqli_fetch_assoc($result)) { - $thread = new Thread(); - $thread->get_from_database($row['thread_id'], $dbc); - } - } - - mysqli_free_result($result); - return $thread; - } -} - -function get_all_categories($dbc) { - $sql = "SELECT cat_id FROM categories ORDER BY cat_id ASC;"; - $result = mysqli_query($dbc, $sql); - - if (!$result) { - echo 'Failed to get categories: ' . mysqli_error($dbc); - } - - $categories = array(); - - if (mysqli_num_rows($result) == 0) { - } else { - while ($row = mysqli_fetch_assoc($result)) { - $category = new Category(); - $category->get_from_database($row['cat_id'], $dbc); - array_push($categories, $category); - } - } - - mysqli_free_result($result); - return $categories; -} \ No newline at end of file -- cgit v1.2.3