<div> <h1>Glasses Inventory</h1> <form method="GET" action="" id="search_form"> Search by model: <input type="text" name="search_term_model" id="search_term" placeholder="Search by Model"> <input type="submit" id="submit" value="Search"> </form> <form method="GET" action="" id="search_form"> Search by brand: <input type="text" name="search_term_brand" id="search_term" placeholder="Search by Brand"> <input type="submit" id="submit" value="Search"> </form> <p>There are <?php echo get_products_count(); ?> total frames</p> <div> <?php global $seekleer_db; $query = 'SELECT * FROM glasses WHERE quantity >= 1 order by entry_date desc LIMIT ' . $pageLimit . ' , ' . $setLimit; $all_results = $seekleer_db->query($query); $all_frames = $all_results->fetchAll(PDO::FETCH_ASSOC); echo '<pre>'; echo displayPaginationForInventory($setLimit, $page); foreach ($all_frames as $frame) { echo displayListViewInventory($frame); } ?>
<?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_products_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: ./"); } // determine the start and end article for the current page; for example, on // page 3 with 8 articles 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);
function get_products_subset($page) { $total_shirts = get_products_count(); $products = get_products_all(); $begin = ($page - 1) * PROD_DISPLAY; return array_slice($products, $begin, PROD_DISPLAY); }