We have curated 0 high-quality AI tools and smart products to help you achieve a more efficient work and lifestyle!
Please start exploring the best tools below
↓
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'], ENT_QUOTES, 'UTF-8') . "";
}
} else {
echo "";
exit();
}
?>
window.location.href = '404';";
exit();
}
// Calculate the offset for the SQL query
$offset = ($current_page - 1) * $products_per_page;
// Fetch total number of products based on the filter
if ($filter === 'all' || empty($filter)) {
// If filter is 'all' or not provided, count all products
$total_products_query = "SELECT COUNT(*) as total FROM products";
} else {
// If filter is set to a specific category, count only the products in that category
$total_products_query = "
SELECT COUNT(*) as total
FROM products p
JOIN categories c ON p.category_id = c.id
WHERE c.c_name = '" . mysqli_real_escape_string($conn, $filter) . "'";
}
$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 based on the filter
if ($filter === 'all' || empty($filter)) {
$products_query = "SELECT * FROM products ORDER BY id DESC LIMIT $offset, $products_per_page";
} else {
$products_query = "
SELECT p.*
FROM products p
JOIN categories c ON p.category_id = c.id
WHERE c.c_name = '" . mysqli_real_escape_string($conn, $filter) . "'
ORDER BY p.id DESC
LIMIT $offset, $products_per_page";
}
$products_result = mysqli_query($conn, $products_query);
if (!$products_result) {
echo "";
exit();
}
if (mysqli_num_rows($products_result) > 0) {
while ($product = mysqli_fetch_assoc($products_result)) {
?>