On Mon, 2004-08-09 at 22:29, Hardik Doshi wrote: > Hello Group, > > I would like to know which one is the most appropriate > way to implement the following scenario. > > For example, I want to display a products catalogue of > 100 products. I do have a base class of product which > contains all the basic property of the product > (Product title, product description, product price > etc)and constructor basically pulls the information > about the product from the DB based on the product > identifier (Primary key). > > Now i have two ways to display catalogue. > > 1. I can write only one query to pull all 100 products > information and store product information to each > product object (With out passing product id to the > constructor) into the collection and later i iterate > that collection to display product catalogue. > (Advantage: less communication with database server > and disadvantage: memory consumption is higher) > > 2. I can initiate an individual product object by > passing product id into the constructor and > constructor will pull an individual product > information from the DB and at the same time i can > display it (Disadvantage: Lots of communication with > database server and Advantage: memory consumption is > less) If you think about inheritance then eventually > this approach will have lots of database calls. > > Please guide me as i am stuck up which way to go. > > Let me know if you need more information.
If you expect the products database to grow much, then solution 2 is your best bet to accommodate much larger numbers. If you expect that you will only ever have a couple of hundred then solution 1 will most likely work nicely. Either way, converting from one style to the other is merely a matter of iterating over retrieved database rows versus iterating over an array of pre-retrieved items. It should take you less time than it took you write your post :) Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php