public static function getProduct($product_id) { $db = Database::getDB(); $query = "SELECT * FROM products\n WHERE productID = '{$product_id}'"; $result = $db->query($query); $row = $result->fetch(); $category = CategoryDB::getCategory($row['categoryID']); $product = new Product($category, $row['productCode'], $row['productName'], $row['listPrice']); $product->setID($row['productID']); return $product; }
public static function getProduct($product_id) { $db = Database::getDB(); $query = 'SELECT * FROM products WHERE productID = :product_id'; $statement = $db->prepare($query); $statement->bindValue(":product_id", $product_id); $statement->execute(); $row = $statement->fetch(); $statement->closeCursor(); $category = CategoryDB::getCategory($row['categoryID']); $product = new Product($category, $row['productCode'], $row['productName'], $row['listPrice']); $product->setID($row['productID']); return $product; }
require '../model/database.php'; require '../model/category.php'; require '../model/category_db.php'; require '../model/product.php'; require '../model/product_db.php'; if (isset($_POST['action'])) { $action = $_POST['action']; } else { if (isset($_GET['action'])) { $action = $_GET['action']; } else { $action = 'list_products'; } } if ($action == 'list_products') { $category_id = $_GET['category_id']; if (empty($category_id)) { $category_id = 1; } $current_category = CategoryDB::getCategory($category_id); $categories = CategoryDB::getCategories(); $products = ProductDB::getProductsByCategory($category_id); include 'product_list.php'; } else { if ($action == 'view_product') { $categories = CategoryDB::getCategories(); $product_id = $_GET['product_id']; $product = ProductDB::getProduct($product_id); include 'product_view.php'; } }
$categoryDB = new CategoryDB(); $productDB = new ProductDB(); $action = filter_input(INPUT_POST, 'action'); if ($action == NULL) { $action = filter_input(INPUT_GET, 'action'); if ($action == NULL) { $action = 'list_products'; } } if ($action == 'list_products') { $category_id = filter_input(INPUT_GET, 'category_id', FILTER_VALIDATE_INT); if ($category_id == NULL || $category_id == FALSE) { $category_id = 1; } // Get product and category data $current_category = $categoryDB->getCategory($category_id); $categories = $categoryDB->getCategories(); $products = $productDB->getProductsByCategory($category_id); // Display the product list include 'product_list.php'; } else { if ($action == 'delete_product') { // Get the IDs $product_id = filter_input(INPUT_POST, 'product_id', FILTER_VALIDATE_INT); $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT); // Delete the product $productDB->deleteProduct($product_id); // Display the Product List page for the current category header("Location: .?category_id={$category_id}"); } else { if ($action == 'show_add_form') {