$page_title"; echo ""; echo ""; ?>
    All"; // Query to fetch up to 6 categories from the database $query = "SELECT * FROM categories LIMIT 6"; $result = mysqli_query($conn, $query); if ($result) { while ($row = mysqli_fetch_assoc($result)) { $active_class = ($filter === $row['c_name']) ? " class='cat_active'" : ""; echo "" . htmlspecialchars($row['c_name']) . ""; } } ?>
    window.location.href = '404';"; exit(); } // Calculate the offset for SQL query $offset = ($current_page - 1) * $products_per_page; // Fetch total number of products matching the search query $safe_query = mysqli_real_escape_string($conn, $search_query); $total_products_query = "SELECT COUNT(*) as total FROM products WHERE title LIKE '%$safe_query%' OR short_description LIKE '%$safe_query%'"; $total_products_result = mysqli_query($conn, $total_products_query); if (!$total_products_result) { echo ""; exit(); } $total_products_row = mysqli_fetch_assoc($total_products_result); $total_products = intval($total_products_row['total']); // Fetch the products for the current page $products_query = "SELECT * FROM products WHERE title LIKE '%$safe_query%' OR short_description LIKE '%$safe_query%' ORDER BY id DESC LIMIT $offset, $products_per_page"; $products_result = mysqli_query($conn, $products_query); if ($products_result && mysqli_num_rows($products_result) > 0) { while ($product = mysqli_fetch_assoc($products_result)) { ?> layui.use('layer', function(){layer.msg('No matching products found. Displaying all products.');});"; // If no results, fetch all products $products_query = "SELECT * FROM products ORDER BY id DESC LIMIT $offset, $products_per_page"; $products_result = mysqli_query($conn, $products_query); while ($product = mysqli_fetch_assoc($products_result)) { ?>
      1): ?>
    • 5): ?>
    • ...
    • ...