That value is calculated using COUNT, which returns the number
of records that match a particular query.
-- Create catalog_count_products_in_category stored procedure
CREATE PROCEDURE catalog_count_products_in_category(IN inCategoryId INT)
BEGIN
SELECT COUNT(*) AS categories_count
FROM product p
INNER JOIN product_category pc
ON p.product_id = pc.product_id
WHERE pc.category_id = inCategoryId;
END$$
catalog_get_products_in_category
This stored procedure returns the products that belong to a certain category. To obtain this list
of products, you need to join the product and product_category tables, as explained earlier in
this chapter. We also trim the product??™s description.
The stored procedure receives four parameters:
??? inCategoryID is the ID for which we??™re returning products.
??? inShortProductDescriptionLength is the maximum length allowed for the product??™s
description. If the description is longer than this value, it will be truncated and ???. . .??? will be
added at the end. Note that this is only used when displaying product lists; in the product
details page, the description won??™t be truncated. You will declare the global value of
this variable later on in config.php, but for now, it is enough to know that it exists and
what its value will be set to: in our case 150 characters.
CHAPTER 5 ?– CREATING THE PRODUCT CATALOG: PART 2 132
??? inProductsPerPage is the maximum number of products our site can display on a single
catalog page.
Pages:
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229