Solved

php data selection and OOP model

Posted on 2011-02-21
5
814 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
[X]
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
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…

630 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