Prev | Current Page 232 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"

Add
the following method to the Catalog class in business/catalog.php:
// Retrieves list of products that belong to a category
public static function GetProductsInCategory(
$categoryId, $pageNo, &$rHowManyPages)
{
// Query that returns the number of products in the category
$sql = 'CALL catalog_count_products_in_category(:category_id)';
// Build the parameters array
$params = array (':category_id' => $categoryId);
// Calculate the number of pages required to display the products
$rHowManyPages = Catalog::HowManyPages($sql, $params);
// Calculate the start item
$start_item = ($pageNo - 1) * PRODUCTS_PER_PAGE;
// Retrieve the list of products
$sql = 'CALL catalog_get_products_in_category(
:category_id, :short_product_description_length,
:products_per_page, :start_item)';
// Build the parameters array
$params = array (
':category_id' => $categoryId,
':short_product_description_length' =>
SHORT_PRODUCT_DESCRIPTION_LENGTH,
':products_per_page' => PRODUCTS_PER_PAGE,
':start_item' => $start_item);
// Execute the query and return the results
return DatabaseHandler::GetAll($sql, $params);
}
This function has two purposes:
??? Calculate the number of subpages of products and return this number through the
&$rHowManyPages parameter. To calculate this number, the HowManyPages() method you
added earlier is used. The SQL query that is used to retrieve the total number of products
calls the catalog_count_products_in_category database stored procedure that you
added earlier to your databases.


Pages:
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244
poker online Paradise Poker spolszczenia świnoujście zasady pokera