Example #1
0
$utils = new Utils();
// get database connection
$database = new Database();
$db = $database->getConnection();
// initialize objects
$product = new Product($db);
$product_image = new ProductImage($db);
$category = new Category($db);
// get category name
$category->id = $category_id;
$category->readOne();
$category_name = $category->name;
// count products under the category
$product->category_id = $category_id;
$products_count = $product->countAll_ByCategory();
// set page title
$page_title = $category_name . " <small>{$products_count} Products</small>";
// include page header HTML
include_once 'layout_head.php';
// read products under a category
$product->category_id = $category_id;
$stmt = $product->readAllByCategory($from_record_num, $records_per_page);
$num = $stmt->rowCount();
// if there are products under a category, display them
if ($num > 0) {
    include_once "read_products_template.php";
} else {
    echo "No products found in this category.";
}
// footer HTML and JavaScript codes
include_once 'layout_foot.php';