summaryrefslogtreecommitdiff
path: root/model/Thread.php
blob: 78d261481c6cc07d7fa6f2780066b808e283e2bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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);
			}
		}
	}
}