diff options
Diffstat (limited to 'model')
-rw-r--r-- | model/Category.php | 36 | ||||
-rw-r--r-- | model/Thread.php | 35 |
2 files changed, 71 insertions, 0 deletions
diff --git a/model/Category.php b/model/Category.php new file mode 100644 index 0000000..d98b08b --- /dev/null +++ b/model/Category.php @@ -0,0 +1,36 @@ +<?php + +class Category { + public $id = 0; + public $name = 'Unknown'; + public $description = 'This category does not exist'; + public $thread_count = 0; + public $post_count = 0; + + function get_from_database($id, $dbc) { + $sql = "SELECT cat_name, cat_description, cat_thread_count, cat_post_count FROM categories WHERE cat_id = " . mysqli_real_escape_string($dbc, $id); + $result = mysqli_query($dbc, $sql); + + if (!$result) { + echo 'Failed to get category: ' . mysqli_error($dbc); + } + + if (mysqli_num_rows($result) == 0) { + echo 'Category does not exist!'; + } else { + while ($row = mysqli_fetch_assoc($result)) { + $this->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); + } + + function get_threads() { + + } +}
\ No newline at end of file diff --git a/model/Thread.php b/model/Thread.php new file mode 100644 index 0000000..78d2614 --- /dev/null +++ b/model/Thread.php @@ -0,0 +1,35 @@ +<?php + +include_once 'Category.php'; + +class Thread { + public $id = 0; + public $subject = 'Unknown thread'; + public $date_created = 0; + public $date_lastpost = 0; + public $category; + public $author; + + function get_from_database($id, $dbc) { + $sql = "SELECT thread_subject, thread_date_created, thread_date_lastpost, thread_category FROM threads WHERE thread_id = " . mysqli_real_escape_string($dbc, $id); + $result = mysqli_query($dbc, $sql); + + if (!$result) { + die('Error trying to display thread page: ' . mysqli_error($dbc)); + } + + if (mysqli_num_rows($result) == 0) { + + } else { + while ($row = mysqli_fetch_assoc($result)) { + $this->id = $id; + $this->subject = $row['thread_subject']; + $this->date_created = $row['thread_date_created']; + $this->date_lastpost = $row['thread_date_lastpost']; + + $this->category = new Category(); + $this->category->get_from_database($row['thread_category'], $dbc); + } + } + } +}
\ No newline at end of file |