コード例 #1
0
ファイル: index.php プロジェクト: j-jm/web182
            include 'product_view.php';
        }
        break;
    case 'list_categories':
        $categories = get_categories();
        include 'category_list.php';
        break;
    case 'add_category':
        $name = filter_input(INPUT_POST, 'name');
        // Validate inputs
        if ($name === NULL) {
            $error = "Invalid category name. Check name and try again.";
            include 'view/error.php';
        } else {
            add_category($name);
            header('Location: .?action=list_categories');
            // display the Category List page
        }
        break;
    case 'delete_category':
        $category_id = filter_input(INPUT_POST, 'category_id', FILTER_VALIDATE_INT);
        $product_count = get_product_count($category_id);
        if ($product_count > 0) {
            display_db_error("This category can't be deleted because it contains products.");
        } else {
            delete_category($category_id);
            header('Location: .?action=list_categories');
            // display the Category List page
        }
        break;
}
コード例 #2
0
ファイル: shirts.php プロジェクト: qdechery/eCommerce-Store
<?php

require_once "../inc/config.php";
require_once ROOT_PATH . "inc/products.php";
// retrieve current page number from query string; set to 1 if blank
if (empty($_GET["pg"])) {
    $current_page = 1;
} else {
    $current_page = $_GET["pg"];
}
// set strings like "frog" to 0; remove decimals
$current_page = intval($current_page);
$total_products = get_product_count();
$products_per_page = 8;
$total_pages = ceil($total_products / $products_per_page);
// redirect too-large page numbers to the last page
if ($current_page > $total_pages) {
    header("Location: ./?pg=" . $total_pages);
}
// redirect too-small page numbers (or strings converted to 0) to the first page
if ($current_page < 1) {
    header("Location: ./");
}
// detemrine the start and end shirt for the current page; for example, on
// page 3 with 8 shirts per page, $start and $end would be 17 and 24
$start = ($current_page - 1) * $products_per_page + 1;
$end = $current_page * $products_per_page;
if ($end > $total_products) {
    $end = $total_products;
}
$products = get_products_subset($start, $end);