Solved

php data selection and OOP model

Posted on 2011-02-21
5
798 Views
Last Modified: 2012-05-11
Hello, I am looking for some OOP suggestion to the following scenario.
I have about 10 selections on the screen, mostly drop downs , they all contribute to the
compound SQL selection  i am trying to run on one file.  Right now, I store
any user's selection in the session  and after submitting, I am allowing for more selection on the
resulting set of data. I* am new to PHP and would like to find out how to implement it using OOP
paradigm and see if it will provide more elegant solution.
0
Comment
Question by:Rozamunda
  • 2
  • 2
5 Comments
 
LVL 20

Expert Comment

by:Mark Brady
Comment Utility
You will have to be more specific. Give an example of what is in the select boxes and what it is you are trying to achieve ?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
You can start your reading here:
http://us.php.net/manual/en/language.oop5.php

Object-oriented programming is designed to encapsulate data and code together.  For a shoe, that might be information that included the product number, the SKU, the size and the color.   Each of these elements of information would be a property of the shoe object.  If you have a warehouse full of shoes and you want to know if one of the pairs is red and size 8, you might create an array of all of the shoe objects and use an iterator like foreach to access each object.  Logically the concept of objects is similar to the concept of associative arrays -- you can refer to the properties of an object by name, just as you can refer to the elements of an associative array by their keys.

So if your client facing form describes a shoe, your input controls would include the product number, size and color.  As the client selected each of these (perhaps through multiple submissions and re-submissions of the form) you would be able to aggregate the information into an object.  Once you had all three of these elements, you would be able to perform a lookup of the SKU and test the inventory to see if you have the desired shoe available in inventory.
0
 

Author Comment

by:Rozamunda
Comment Utility
Ray, yes this is what it look like in my scenario.

So you would envision an object with all the selections ?.
How to preserve the selection between submissions ?.
Should I serialize it to a session ?

Are there any benefits with this approach ?

Any code snippets maybe ?

Thanks
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
Yes, you might have an object to contain the selections.  The class definition would have "setters" and "getters" -- methods to add and retrieve information in the object.  You can serialize most objects and store them in the session (you can also use an array inside the session, and that might be an easy way to handle this).

I'll see if I can come up with an example.  It will be a little later today.
0
 

Author Closing Comment

by:Rozamunda
Comment Utility
Partially answered my question
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now