Prev | Current Page 496 | Next

Emilian Balanescu and Cristian Darie

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

tpl';
}
}
}
?>
How It Works: The Shopping Cart Admin Page
The hard work of the shopping cart admin page is done by the two stored procedures you??™ve added to the
tshirtshop database: shopping_cart_count_old_carts and shopping_cart_delete_old_carts.
They both receive as a parameter the number of days that determine when a shopping cart is old, and they use the
same logic to calculate the shopping cart elements that are old and should be removed.
The age of a shopping cart is given by the age of the most recently added or changed item and is calculated using
the GROUP BY SQL clause. The following is the condition that establishes whether a cart should be considered old:
WHERE cart_id IN
(SELECT cart_id
FROM (SELECT cart_id
FROM shopping_cart
GROUP BY cart_id
HAVING DATE_SUB(NOW(), INTERVAL inDays DAY) >=
MAX(added_on))
AS sc);
The two nested subqueries are necessary to overcome a MySQL limitation that doesn??™t allow selecting from a table
that is being updated.
Summary
In this chapter, you learned how to store the shopping cart information in the database, and
you learned a few other things in the process as well. Probably the most interesting was the
way you can store the shopping cart ID as a cookie on the client, because you haven??™t done
anything similar so far in this book.
After working through the process of creating the shopping cart, starting with the
database and ending with the presentation tier, we also touched on the new administrative
challenges.


Pages:
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
spolszczenia Poker Porady przeprowadzki katowice Cd Poker Titan Poker