Solved

php data selection and OOP model

Posted on 2011-02-21
5
807 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
ID: 34950124
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 110

Expert Comment

by:Ray Paseur
ID: 34951217
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
ID: 34952088
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 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 34954196
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
ID: 34971658
Partially answered my question
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

733 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