Prev | Current Page 491 | Next

Emilian Balanescu and Cristian Darie

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

On a high-activity web site, the shopping_cart table
can grow very large.
With the current version of the code, shopping cart IDs are stored at the client browser for
seven days. As a result, you can assume that any shopping carts that haven??™t been updated in
the last ten days are invalid and can be safely removed.
In the following exercise, you??™ll quickly implement a simple shopping cart administration
page, where the administrator can see how many old shopping cart entries exist and can delete
them if necessary. Figure 12-5 shows this page.
Figure 12-5. Administering shopping carts
The most interesting aspect you need to understand is the SQL logic that deletes all shopping
carts that haven??™t been updated in a certain amount of time. This isn??™t as simple as it sounds??”at
first sight, you might think all you have to do is delete all the records in shopping_cart whose
added_on is older than a specified date. However, this strategy doesn??™t work with shopping carts
that are modified over time (say the visitor has been adding items to the cart each week in the
past three months). If the last change to the shopping cart is recent, none of its elements should
be deleted, even if some are very old. In other words, you should either remove all elements in
a shopping cart or remove none of them. The age of a shopping cart is given by the age of its most
recently modified or added product.


Pages:
479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
eko mama szkoła narciarska określić Prince lion Prywatny Ośrodek Terapii uzależnień