jcanker Posted June 30, 2010 Share Posted June 30, 2010 Bear with me--I've been doing php for a while, but am new to OO PHP... In short, I'm trying to create a computing environment inventory/change checklist to use for when my business customers are moving or changing their business computing environment (adding servers/PCs, etc). Rather than create a ginormous amout of session variables to track the inventory as it is built and edited as a result of using the web checklist interface, I'd like to create an object for each PC, Server, Router, Printer, etc. I'm planning on creating an attribute for each object, "type," the value of which would be "server," "PC," "Printer," etc. If I want to cycle through all the PC's for instance, how would I cycle through all the current objects that have attribute type "PC"? In other words, what is the best way to approach the code and MySQL storage that when I want to see all the PCs and display their attributes such as "name" and "installed software" I can do so? Also, just to be clear, I'm not expecting anyone to spend a bunch of time writing the code for me. If you can just point me in the right direction and maybe include a short example of a specific step, I would GREATLY appreciate it. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/206308-cycle-through-php-objects-by-attribute-value/ Share on other sites More sharing options...
ChemicalBliss Posted June 30, 2010 Share Posted June 30, 2010 Just to confirm, all this data is in a database right? Give us the database structure and im sure someone can get you started. -cb- Quote Link to comment https://forums.phpfreaks.com/topic/206308-cycle-through-php-objects-by-attribute-value/#findComment-1079336 Share on other sites More sharing options...
trq Posted July 1, 2010 Share Posted July 1, 2010 Firstly, objects (in any language) are used to describe 'things' of a specific 'type'. So making one generic 'thing' object and setting a 'type' property isn't likely to be a good design. If these 'things' share attributes however you could have your objects inherit from a 'base' object which defined all the common attributes. Next, objects don't persist by themselves. So, if your going to be storing there data within a database, just query the database for the data you need. No need to make objects that your not going to use. Quote Link to comment https://forums.phpfreaks.com/topic/206308-cycle-through-php-objects-by-attribute-value/#findComment-1079569 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.