Address changes.
This commit is contained in:
parent
a5949e0401
commit
635b3ddcbc
59 changed files with 7249 additions and 2745 deletions
118
search.php
Normal file
118
search.php
Normal file
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
require_once 'includes/globals.php';
|
||||
$title = "Search Results";
|
||||
require_once 'includes/header.php';
|
||||
|
||||
// Get the search query and current page.
|
||||
$query = isset($_GET['q']) ? trim($_GET['q']) : '';
|
||||
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
|
||||
$resultsPerPage = 10;
|
||||
|
||||
if (empty($query)) {
|
||||
echo "<div class='container py-5'><div class='alert alert-warning'>Please enter a search query.</div></div>";
|
||||
require_once 'includes/footer.php';
|
||||
exit;
|
||||
}
|
||||
|
||||
// Instantiate the classes using your DB connection.
|
||||
use DJMixHosting\DJs;
|
||||
use DJMixHosting\Genres;
|
||||
use DJMixHosting\Mixshows;
|
||||
use DJMixHosting\Database;
|
||||
use DJMixHosting\Mixes;
|
||||
|
||||
$db = new Database($config);
|
||||
|
||||
$djsObj = new DJs($db);
|
||||
$genresObj = new Genres($db);
|
||||
$mixshowsObj = new Mixshows($db);
|
||||
$mixesObj = new Mixes($db);
|
||||
|
||||
// Execute the search methods.
|
||||
$djsResults = $djsObj->search($query, $page, $resultsPerPage);
|
||||
$genresResults = $genresObj->search($query, $page, $resultsPerPage);
|
||||
$mixshowsResults = $mixshowsObj->search($query, $page, $resultsPerPage);
|
||||
$mixesResults = $mixesObj->search($query, $page, $resultsPerPage);
|
||||
|
||||
// Combine and label results.
|
||||
$results = [];
|
||||
|
||||
foreach ($djsResults as $result) {
|
||||
$result['type'] = 'DJ';
|
||||
$results[] = $result;
|
||||
}
|
||||
foreach ($genresResults as $result) {
|
||||
$result['type'] = 'Genre';
|
||||
$results[] = $result;
|
||||
}
|
||||
foreach ($mixshowsResults as $result) {
|
||||
$result['type'] = 'Mixshow';
|
||||
$results[] = $result;
|
||||
}
|
||||
foreach ($mixesResults as $result) {
|
||||
$result['type'] = 'Mix';
|
||||
// Rename title field to name for consistency.
|
||||
$result['name'] = $result['title'];
|
||||
$results[] = $result;
|
||||
}
|
||||
|
||||
// (Optional) You can sort the combined results here if needed.
|
||||
?>
|
||||
|
||||
<section>
|
||||
<div class="container py-5">
|
||||
<!-- Breadcrumb -->
|
||||
<nav aria-label="breadcrumb" class="bg-body-tertiary rounded-3 p-3 mb-4">
|
||||
<ol class="breadcrumb mb-0">
|
||||
<li class="breadcrumb-item"><a href="/"><?php echo $locale['home']; ?></a></li>
|
||||
<li class="breadcrumb-item active" aria-current="page">Search</li>
|
||||
</ol>
|
||||
</nav>
|
||||
|
||||
<!-- Search Heading -->
|
||||
<h1 class="mb-4">Search Results for "<span class="text-primary"><?php echo htmlspecialchars($query); ?></span>"</h1>
|
||||
|
||||
<?php if (empty($results)): ?>
|
||||
<div class="alert alert-info">No results found for your search query.</div>
|
||||
<?php else: ?>
|
||||
<div class="row">
|
||||
<?php foreach ($results as $result): ?>
|
||||
<div class="col-md-6 mb-4">
|
||||
<div class="card h-100 shadow-sm">
|
||||
<div class="card-body">
|
||||
<h5 class="card-title">
|
||||
<?php echo htmlspecialchars($result['name']); ?>
|
||||
<span class="badge bg-secondary ms-2"><?php echo htmlspecialchars($result['type']); ?></span>
|
||||
</h5>
|
||||
<p class="card-text">
|
||||
<?php echo htmlspecialchars($result['bio'] ?? $result['description'] ?? ''); ?>
|
||||
</p>
|
||||
</div>
|
||||
<?php if (isset($result['slug'])): ?>
|
||||
<div class="card-footer text-end bg-transparent border-0">
|
||||
<a href="/<?php echo strtolower($result['type']); ?>/<?php echo htmlspecialchars($result['slug']); ?>" class="btn btn-sm btn-primary">View Details</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Pagination -->
|
||||
<nav aria-label="Search result pages">
|
||||
<ul class="pagination justify-content-center">
|
||||
<?php if ($page > 1): ?>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="/search.php?q=<?php echo urlencode($query); ?>&page=<?php echo $page - 1; ?>">Previous</a>
|
||||
</li>
|
||||
<?php endif; ?>
|
||||
<li class="page-item">
|
||||
<a class="page-link" href="/search.php?q=<?php echo urlencode($query); ?>&page=<?php echo $page + 1; ?>">Next</a>
|
||||
</li>
|
||||
</ul>
|
||||
</nav>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<?php require_once 'includes/footer.php'; ?>
|
Loading…
Add table
Add a link
Reference in a new issue