diff options
Diffstat (limited to 'model/Category.php')
-rw-r--r-- | model/Category.php | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/model/Category.php b/model/Category.php index d98b08b..ffd903c 100644 --- a/model/Category.php +++ b/model/Category.php @@ -1,5 +1,7 @@ <?php +include_once 'Thread.php'; + class Category { public $id = 0; public $name = 'Unknown'; @@ -30,7 +32,49 @@ class Category { mysqli_free_result($result); } - function get_threads() { - + function get_threads($dbc) { + $sql = "SELECT thread_id FROM threads WHERE thread_category = " . $this->id; + $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_all_categories($dbc) { + $sql = "SELECT cat_id FROM categories"; + $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 |