source: businesses.php

Last change on this file was 0791611, checked in by sstalevska <sara.stalevska@…>, 2 years ago

Push the entire project.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1<?php
2require_once('./inc/common.php');
3
4$pageTitle = 'Businesses';
5$pageSlug = 'businesses';
6
7require_once('./inc/head.php');
8require_once('./inc/header.php');
9?>
10<div class="container">
11 <h1 class="mt-5"><?= $pageTitle ?></h1>
12
13 <?php require_once('./inc/alerts-err.php'); ?>
14
15 <p class="lead mb-4">This is a list of all businesses. Select a business to view its details.</p>
16
17 <div class="row row-cols-1 row-cols-md-2 row-cols-lg-3 row-cols-xl-4 g-4">
18 <?php
19 $i = 0;
20 /**
21 * Fetch all businesses and display them in a list as cards.
22 */
23 $sql = '
24 select
25 b.business_id,
26 b.business_name,
27 (
28 select avg(r.review_stars)
29 from review r
30 where r.business_id = b.business_id
31 ) as business_avg_stars,
32 c.category_id,
33 c.category_name,
34 (
35 select string_agg(a.address_city, \'; \') as address_city
36 from address a
37 where a.business_id = b.business_id
38 limit 1
39 ) as address_city
40 from business b
41 join category c on
42 b.category_id = c.category_id
43 order by b.business_name';
44 foreach ($conn->query($sql) as $row) {
45 $i++;
46 ?>
47 <div class="col">
48 <div class="card shadow-sm">
49 <div class="card-body">
50 <h5 class="card-title" style="min-height: 2.5em;">
51 <a href="/business.php?id=<?= $row['business_id'] ?>"><?= $row['business_name'] ?></a>
52 </h5>
53 <div><?= $row['category_name'] ?></div>
54 <div><?= $row['address_city'] ?></div>
55 <?= outputStars($row['business_avg_stars']) ?>
56 <a class="btn btn-sm btn-dark mt-3" href="/business.php?id=<?= $row['business_id'] ?>">View</a>
57 </div>
58 </div>
59 </div>
60 <?php } ?>
61 </div>
62</div>
63<?php
64require_once('./inc/footer.php');
Note: See TracBrowser for help on using the repository browser.