Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php data selection and OOP model

Posted on 2011-02-21
5
Medium Priority
?
826 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 750 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to implement server side field validation and display customized error messages to the client.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

971 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