<?php

include 'includes/header.php';
// create DB object
$db = new Database();
$st = new Story();
$ca = new Category();
// check url for category
if (isset($_GET['category'])) {
    $category = $_GET['category'];
    $stories = $db->select($st->getStoryByCategory($category));
    $cat = $db->select($ca->getCategoryById($category))->fetch_assoc();
} else {
    $stories = $db->select($st->getAllStories());
}
$categories = $db->select($st->getStoryCategories());
?>

<div class="container">
  <div class="header">
    <h1 class="title">Stories</h1>
    <?php 
if (isset($category)) {
    ?>
      <p class="lead description">Stories in the <?php 
    echo $cat['Name'];
    ?>
 category</p>
    <?php 
} else {
    ?>