87 lines
4.2 KiB
PHP
87 lines
4.2 KiB
PHP
<?php
|
|
require_once 'includes/header.php';
|
|
require_once 'db/config.php';
|
|
|
|
$query = $_GET['q'] ?? '';
|
|
$results = [];
|
|
|
|
if (!empty($query)) {
|
|
try {
|
|
$db = db();
|
|
$stmt = $db->prepare(
|
|
'SELECT * FROM listings WHERE (name LIKE :query OR description LIKE :query OR category LIKE :query) AND is_verified = 1'
|
|
);
|
|
$stmt->bindValue(':query', '%' . $query . '%');
|
|
$stmt->execute();
|
|
$results = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
// In a real application, log this error instead of displaying it.
|
|
error_log('Search query failed: ' . $e->getMessage());
|
|
// Optionally, set a user-friendly error message.
|
|
$error_message = "Sorry, we couldn't perform the search at this time. Please try again later.";
|
|
}
|
|
}
|
|
?>
|
|
|
|
<section class="search-results-section">
|
|
<div class="container">
|
|
<h1 class="mb-4">Search Results</h1>
|
|
|
|
<div class="row">
|
|
<div class="col-lg-8 mx-auto">
|
|
<div class="search-bar mb-5">
|
|
<form action="search.php" method="get">
|
|
<div class="input-group">
|
|
<input type="text" name="q" class="form-control" placeholder="Search again..." value="<?php echo htmlspecialchars($query); ?>" aria-label="Search">
|
|
<button class="btn" type="submit"><i class="bi bi-search"></i></button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if (isset($error_message)): ?>
|
|
<div class="alert alert-danger text-center">
|
|
<?php echo $error_message; ?>
|
|
</div>
|
|
<?php elseif (!empty($query)): ?>
|
|
<?php if (count($results) > 0): ?>
|
|
<p class="text-center mb-4">Found <?php echo count($results); ?> verified listing(s) matching your search.</p>
|
|
<div class="row g-4">
|
|
<?php foreach ($results as $listing): ?>
|
|
<div class="col-md-6 col-lg-4">
|
|
<div class="listing-card">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($listing['name']); ?></h5>
|
|
<h6 class="card-subtitle mb-2 text-muted"><?php echo htmlspecialchars($listing['category']); ?></h6>
|
|
<p class="card-text"><?php echo htmlspecialchars($listing['description']); ?></p>
|
|
<ul class="list-unstyled">
|
|
<?php if ($listing['address']): ?>
|
|
<li><i class="bi bi-geo-alt-fill"></i> <?php echo htmlspecialchars($listing['address']); ?></li>
|
|
<?php endif; ?>
|
|
<?php if ($listing['phone']): ?>
|
|
<li><i class="bi bi-telephone-fill"></i> <?php echo htmlspecialchars($listing['phone']); ?></li>
|
|
<?php endif; ?>
|
|
<?php if ($listing['website']): ?>
|
|
<li><i class="bi bi-globe"></i> <a href="<?php echo htmlspecialchars($listing['website']); ?>" target="_blank" rel="noopener noreferrer">Visit Website</a></li>
|
|
<?php endif; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="text-center">
|
|
<img src="assets/images/no_results.svg" alt="No Results Found" style="max-width: 200px;" class="mb-3">
|
|
<h4>No Verified Listings Found</h4>
|
|
<p>We couldn't find any verified businesses matching "<?php echo htmlspecialchars($query); ?>".</p>
|
|
<p>Try searching for something else or browse our categories.</p>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</section>
|
|
|
|
<?php require_once 'includes/footer.php'; ?>
|