prepare("SELECT DISTINCT brand FROM products WHERE MATCH(name, brand) AGAINST(? IN BOOLEAN MODE) AND brand IS NOT NULL ORDER BY brand"); $brand_stmt->execute(["*" . $query . "*"]); $brands = $brand_stmt->fetchAll(PDO::FETCH_COLUMN); // Sorting logic switch ($sort) { case 'price_asc': $sql .= " ORDER BY (SELECT MIN(effective_price) FROM product_listings WHERE product_id = p.id) ASC"; break; case 'price_desc': $sql .= " ORDER BY (SELECT MIN(effective_price) FROM product_listings WHERE product_id = p.id) DESC"; break; case 'rating': $sql .= " ORDER BY (SELECT AVG(rating) FROM product_listings WHERE product_id = p.id) DESC"; break; default: // Default is relevance, no extra ORDER BY needed for MATCH...AGAINST break; } // 1. Search for products $stmt = $pdo->prepare($sql); $stmt->execute($params); $products = $stmt->fetchAll(PDO::FETCH_ASSOC); $product_ids = array_column($products, 'id'); if (!empty($product_ids)) { $placeholders = implode(',', array_fill(0, count($product_ids), '?')); $stmt = $pdo->prepare("SELECT *, pl.id as listing_id, plat.name as platform_name FROM product_listings pl JOIN platforms plat ON pl.platform_id = plat.id WHERE pl.product_id IN ($placeholders)"); $stmt->execute($product_ids); $listings = $stmt->fetchAll(PDO::FETCH_ASSOC); $listings_by_product = []; foreach ($listings as $listing) { $listings_by_product[$listing['product_id']][] = $listing; } foreach ($products as $product) { $product['listings'] = $listings_by_product[$product['id']] ?? []; if (!empty($product['listings'])) { $cheapest = array_reduce($product['listings'], fn($c, $i) => ($c === null || $i['effective_price'] < $c['effective_price']) ? $i : $c); $product['cheapest_price'] = $cheapest['effective_price']; $product['badge'] = $cheapest['badge']; } $results[] = $product; } } } ?> Search Results for "<?php echo htmlspecialchars($query); ?>" - XUPER MALL
← Back to Home

Search Results for ""

No products found matching your search.
<?php echo htmlspecialchars($product['name']); ?>

From: $

Available on: