1 | <?php
|
---|
2 | require_once('./inc/common.php');
|
---|
3 |
|
---|
4 | /**
|
---|
5 | * Check whether the required parameter ID is sent. Go back with an error message if not.
|
---|
6 | */
|
---|
7 | if ((! isset($_GET['id'])) || (empty($_GET['id'])) || (! is_numeric($_GET['id']))) {
|
---|
8 | header('Location: /categories.php?err=no_id');
|
---|
9 | exit();
|
---|
10 | }
|
---|
11 | $category_id = $_GET['id'];
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Get the name of this category (needed for the page title).
|
---|
15 | */
|
---|
16 | $sql = 'SELECT category_name FROM category WHERE category_id = :id';
|
---|
17 | $stm = $conn->prepare($sql);
|
---|
18 | $stm->execute([':id' => $category_id]);
|
---|
19 | $category_name = $stm->fetch()[0];
|
---|
20 | /**
|
---|
21 | * Go back with an error message if the category with this id does not exist.
|
---|
22 | */
|
---|
23 | if (empty($category_name)) {
|
---|
24 | header('Location: /categories.php?err=bad_id');
|
---|
25 | exit();
|
---|
26 | }
|
---|
27 |
|
---|
28 | $pageTitle = 'Category: ' . $category_name;
|
---|
29 | $pageSlug = 'categories';
|
---|
30 |
|
---|
31 | require_once('./inc/head.php');
|
---|
32 | require_once('./inc/header.php');
|
---|
33 | ?>
|
---|
34 | <div class="container">
|
---|
35 | <h1 class="mt-5"><?= $pageTitle ?></h1>
|
---|
36 |
|
---|
37 | <p class="lead mb-4">This is a list of all businesses that belong to the category "<?= $category_name ?>". Select a business to view its details.</p>
|
---|
38 |
|
---|
39 | <table class="table">
|
---|
40 | <thead>
|
---|
41 | <tr>
|
---|
42 | <th width="1"><abbr title="Number">#</abbr></th>
|
---|
43 | <th>Business Name</th>
|
---|
44 | <th width="1">Action</th>
|
---|
45 | </tr>
|
---|
46 | </thead>
|
---|
47 | <tbody>
|
---|
48 | <?php
|
---|
49 | /**
|
---|
50 | * Fetch the details of the category with the given id.
|
---|
51 | */
|
---|
52 | $i = 0;
|
---|
53 | $sql = 'SELECT business_id, business_name FROM business WHERE category_id = :id ORDER BY business_name';
|
---|
54 | $stm = $conn->prepare($sql);
|
---|
55 | $stm->execute([':id' => $category_id]);
|
---|
56 | foreach ($stm->fetchAll() as $row) {
|
---|
57 | $i++;
|
---|
58 | ?>
|
---|
59 | <tr>
|
---|
60 | <td class="text-end"><?= $i ?>.</td>
|
---|
61 | <td><a href="/business.php?id=<?= $row['business_id'] ?>"><?= $row['business_name'] ?></a></td>
|
---|
62 | <td><a class="btn btn-sm btn-dark" href="/business.php?id=<?= $row['business_id'] ?>">View</a></td>
|
---|
63 | </tr>
|
---|
64 | <?php } ?>
|
---|
65 | </tbody>
|
---|
66 | </table>
|
---|
67 | </div>
|
---|
68 | <?php
|
---|
69 | require_once('./inc/footer.php');
|
---|