Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

php data selection and OOP model

Posted on 2011-02-21
5
805 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 109

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 109

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

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…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.

839 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