diff options
| author | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-21 17:29:58 -0600 | 
|---|---|---|
| committer | cflip <36554078+cflip@users.noreply.github.com> | 2021-03-21 17:29:58 -0600 | 
| commit | 7ef208fc1ae5a24d7b3cd2e22e969285fbf7262a (patch) | |
| tree | 7995fdce15426408ea1f893c6842dc63cd2b2fae /model/Category.php | |
| parent | d0e23fd32cd2c968bdb905604c543b8c1bb8f6ee (diff) | |
Add additional classes and functions
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 | 
