Jump to content
Larry Ullman's Book Forums

The Header And The While Loop In List_Products.Html Template

Recommended Posts

Hi Larry, great book, finding it really clear and useful.


Thought I'd just ask about the style of coding you've used to display the products in the list_products.html file.


You include the header div for that page within the while loop, only echoing it on the first iteration. It uses the g_description and g_image columns from the first row.


My problem is that, g_description and g_image are still in every other row of the mysql result. They are identical to those in the first row and are never used. I can't help but feel it's a shame to have called for them in the first place.


Have you done it this way to minimize calls to the database?


The way I might be tempted to write this page, is to get the category details in a separate database call, then I could take the header completely out of the while loop, and there wouldn't be a need for the if (!$header){ condition.


Hope that makes sense to you. Just wondering what your thoughts on this were?


Thanks for reading!

Link to comment
Share on other sites

Yes, I've done this to minimize database calls. If you fetch the description and image separately, then you have two calls and two result sets to deal with, even though you have less total data to handle. But database interactions tend to be the most expensive actions you can take (in terms of server resources) and ought to be kept to a minimum.

Link to comment
Share on other sites


  • Create New...