prepare('SELECT COUNT(*) AS total FROM products p ' . $where); if ($search) $stmt->bindParam('search', $param3, PDO::PARAM_STR); $stmt->execute(); $products_total = $stmt->fetchColumn(); // SQL query to get all products from the "products" table $stmt = $pdo->prepare('SELECT p.*, GROUP_CONCAT(m2.full_path) AS imgs FROM products p LEFT JOIN (SELECT pm.id, pm.product_id, m.full_path FROM products_media pm JOIN media m ON m.id = pm.media_id GROUP BY pm.id, pm.product_id, m.full_path) m2 ON m2.product_id = p.id ' . $where . ' GROUP BY p.id, p.name, p.description, p.price, p.rrp, p.quantity, p.date_added, p.weight, p.url_slug, p.status ORDER BY ' . $order_by . ' ' . $order . ' LIMIT :start_results,:num_results'); // Bind params $stmt->bindParam('start_results', $param1, PDO::PARAM_INT); $stmt->bindParam('num_results', $param2, PDO::PARAM_INT); if ($search) $stmt->bindParam('search', $param3, PDO::PARAM_STR); $stmt->execute(); // Retrieve query results $products = $stmt->fetchAll(PDO::FETCH_ASSOC); // Delete product if (isset($_GET['delete'])) { // Delete the product $stmt = $pdo->prepare('DELETE p, pm, po, pc FROM products p LEFT JOIN products_media pm ON pm.product_id = p.id LEFT JOIN products_options po ON po.product_id = p.id LEFT JOIN products_categories pc ON pc.product_id = p.id WHERE p.id = ?'); $stmt->execute([ $_GET['delete'] ]); // Clear session cart if (isset($_SESSION['cart'])) { unset($_SESSION['cart']); } header('Location: index.php?page=products&success_msg=3'); exit; } // Handle success messages if (isset($_GET['success_msg'])) { if ($_GET['success_msg'] == 1) { $success_msg = 'Product created successfully!'; } if ($_GET['success_msg'] == 2) { $success_msg = 'Product updated successfully!'; } if ($_GET['success_msg'] == 3) { $success_msg = 'Product deleted successfully!'; } } // Determine the URL $url = 'index.php?page=products&search=' . $search . '&status=' . $status . '&quantity=' . $quantity; ?> =template_admin_header('Products', 'products', 'view')?>
View, manage, and search products.
=$success_msg?>
| # | Productcode | Name | Price | Quantity | Images | Date Added | Status | Actions | |
| There are no products | |||||||||
| =$product['id']?> | =$product['productcode']?> | =$product['name']?> | =currency_code?>=number_format($product['price'], 2)?> | =currency_code?>=number_format($product['price'], 2)?> |
=$product['quantity']==-1?'--':number_format($product['quantity'])?> |
|
=date('F j, Y', strtotime($product['date_added']))?> | =$product['status'] ? 'Enabled' : 'Disabled'?> | Edit |