[0791611] | 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: /services.php?err=no_id');
|
---|
| 9 | exit();
|
---|
| 10 | }
|
---|
| 11 | $service_id = $_GET['id'];
|
---|
| 12 |
|
---|
| 13 | /**
|
---|
| 14 | * Get the name of this service (needed for the page title).
|
---|
| 15 | */
|
---|
| 16 | $sql = 'SELECT service_name FROM service WHERE service_id = :id';
|
---|
| 17 | $stm = $conn->prepare($sql);
|
---|
| 18 | $stm->execute([':id' => $service_id]);
|
---|
| 19 | $service_name = $stm->fetch()[0];
|
---|
| 20 | /**
|
---|
| 21 | * Go back with an error message if the service with this id does not exist.
|
---|
| 22 | */
|
---|
| 23 | if (empty($service_name)) {
|
---|
| 24 | header('Location: /services.php?err=bad_id');
|
---|
| 25 | exit();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | $pageTitle = 'Service: ' . $service_name;
|
---|
| 29 | $pageSlug = 'services';
|
---|
| 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 offer the service "<?= $service_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 service with the given service id and display it in a tabular format.
|
---|
| 51 | */
|
---|
| 52 | $i = 0;
|
---|
| 53 | $sql = 'SELECT b.business_id, b.business_name FROM business_service bs join business b on bs.business_id = b.business_id WHERE bs.service_id = :id ORDER BY b.business_name';
|
---|
| 54 | $stm = $conn->prepare($sql);
|
---|
| 55 | $stm->execute([':id' => $service_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');
|
---|