38283-vm/search.php
2026-02-08 08:34:40 +00:00

65 lines
3.3 KiB
PHP

<?php
include 'includes/header.php';
$q = $_GET['q'] ?? '';
$results = [];
if (!empty($q)) {
$stmt = db()->prepare("SELECT p.*, c.name as cat_name FROM products p JOIN categories c ON p.category_id = c.id WHERE p.name LIKE ? OR p.description LIKE ? OR c.name LIKE ? ORDER BY p.id DESC");
$stmt->execute(['%'.$q.'%', '%'.$q.'%', '%'.$q.'%']);
$results = $stmt->fetchAll();
}
?>
<div class="row mb-5 align-items-center">
<div class="col-md-6">
<h1 class="fw-bold text-white mb-0">搜索结果</h1>
<p class="text-muted mt-2">关键词: <span class="text-primary fw-bold">"<?php echo htmlspecialchars($q); ?>"</span></p>
</div>
<div class="col-md-6 text-md-end mt-3 mt-md-0">
<span class="badge bg-primary bg-opacity-25 text-primary rounded-pill px-4 py-2 border border-primary border-opacity-25"><?php echo count($results); ?> 个相关结果</span>
</div>
</div>
<?php if (empty($results)): ?>
<div class="text-center py-5">
<div class="glass-card p-5">
<i class="bi bi-search fs-1 text-muted d-block mb-3"></i>
<h4 class="text-white">未找到相关结果</h4>
<p class="text-muted">换个关键词试试,或者联系客服定制您需要的软件。</p>
<a href="index.php" class="btn btn-primary mt-3 px-5 rounded-pill">返回商城首页</a>
</div>
</div>
<?php else: ?>
<div class="row g-4">
<?php foreach ($results as $product): ?>
<div class="col-6 col-lg-3">
<div class="glass-card p-3 product-card h-100 d-flex flex-column">
<div class="product-img-container mb-3">
<a href="product.php?id=<?php echo $product['id']; ?>">
<img src="<?php echo $product['image_url']; ?>" class="product-img" alt="<?php echo $product['name']; ?>">
<?php if ($product['is_hot']): ?>
<span class="badge-hot">HOT</span>
<?php endif; ?>
</a>
</div>
<div class="px-2 flex-grow-1 d-flex flex-column">
<span class="text-muted small"><?php echo $product['cat_name']; ?></span>
<h5 class="text-white mb-3">
<a href="product.php?id=<?php echo $product['id']; ?>" class="text-white text-decoration-none hover-primary">
<?php echo $product['name']; ?>
</a>
</h5>
<div class="mt-auto d-flex justify-content-between align-items-center">
<span class="price-tag"><?php echo $product['price_usdt']; ?> <small class="small">USDT</small></span>
<button class="btn btn-sm btn-outline-primary rounded-circle" onclick="addToCart(<?php echo $product['id']; ?>, '<?php echo addslashes($product['name']); ?>', <?php echo $product['price_usdt']; ?>, '<?php echo $product['image_url']; ?>')">
<i class="bi bi-cart-plus"></i>
</button>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php include 'includes/footer.php'; ?>