Prev | Current Page 233 | Next

Emilian Balanescu and Cristian Darie

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


??? Return the list of products in the mentioned category.
CHAPTER 5 ?–  CREATING THE PRODUCT CATALOG: PART 2 143
?– Note The ampersand (&) before a function parameter means it is passed by reference. When a variable is
passed by reference, an alias of the variable is passed instead of creating a new copy of the value. This way,
when a variable is passed by reference and the called function changes its value, its new value will be
reflected in the caller function, too. Passing by reference is an alternative method to receiving a return value
from a called function and is particularly useful when you need to get multiple return values from the called
function. CreateSubpageQuery() returns the text of a SELECT query through its return value and the total
number of subpages through the $rHowManyPages parameter that is passed by reference.
GetProductsOnDepartment
The GetProductsOnDepartment() method returns the list of products featured for a particular
department. The department??™s featured products must be displayed when the customer visits
the home page of a department. Put it inside the Catalog class:
// Retrieves the list of products for the department page
public static function GetProductsOnDepartment(
$departmentId, $pageNo, &$rHowManyPages)
{
// Query that returns the number of products in the department page
$sql = 'CALL catalog_count_products_on_department(:department_id)';
// Build the parameters array
$params = array (':department_id' => $departmentId);
// 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_on_department(
:department_id, :short_product_description_length,
:products_per_page, :start_item)';
// Build the parameters array
$params = array (
':department_id' => $departmentId,
':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);
}
CHAPTER 5 ?–  CREATING THE PRODUCT CATALOG: PART 2 144
GetProductsOnCatalog
The GetProductsOnCatalog() method returns the list of products featured on the catalog??™s
front page.


Pages:
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245