load an array of class instances
Posted: Fri Aug 07, 2009 7:29 pm
Rather then make continued calls to my database I'd like to load the contents of several tables into classes, do the manipulation of data within the class and at the end of the program update the database from the values in the class instances. The question I have is does anyone have or could you point me to examples of code on how to load multiple class instances into an array. For instance, I do a query and get the recordset from the database. Now I've defined my class and the constructor's parameters are the same as the fields found in the record. I can see how to do this for a single instance of the class, or for multiple instances of the class using different a name for each instance. What I can't figure out is the syntax to load the new class instance into an array, giving me an array of class instances. Speaking of the array, to load the class instance into the array does the array have to be a regular array, which I'd have to iterate through to find the correct instance/db record, or is there any way to build an associative array of the class instances using the ID of the record as the index, which would make it faster to retrieve the data?
In short does anyone have code examples of how to build an array of class instances and retrieve the values from that array?
Thanks,
Tom
In short does anyone have code examples of how to build an array of class instances and retrieve the values from that array?
Thanks,
Tom