Little logic help needed for my project

Hello all,

as I knew a little bit of PHP, I accepted a project from a friend !
This project is all about developing a tool to make calculations based on a lot of variables.
Unfortunately, at this moment I’m stuck and I just need some logical thinking help to know what is the best way to advance.

I don’t know how to explain all in detail, but let me give a try :

  1. The user can open, edit, delete, create a lot of new items, all in different tables
  2. At the moment all data is entered, they will open a “start calculation” page
  3. In that page, they first select 1 kind/type of calculation to make
  4. Based on that selection, a new page is opened, showing a list of items that belong to that kind of calculation. The list shows the name and a numeric field (with a spinner)
  5. The user can delete items off the list, add items to the list, change the number for each item. This is like a kind of “cart” in the memory.

Stage on which I’m blocked:

  1. Once all items are selected, a next screen should come available, showing the selected items, but with data from the table of each item separately. The user should be able to enter extra data for each item, select materials for each item and check checkboxes depending on their choice. At the end, they should come in a calculation page showing the calculations based on all the selections in the former screen.

Why am I blocked ? Because I don’t know how to continue from here.
Is it best to keep on working with the cart ? If yes, how can I make the cart contain all the extra data ?
Should I start working with classes ? Importing all data from the table and start using them as objects?
Use another way ?

I’m really stuck as I’m missing the next logical step, and off course the best way to continue in next steps.

I was hoping to find some help here… And I would be very thankfull…

Greetings and thanks in advance,

Davy

In order to provide a more concrete answer, I’ll need to see at least part of the code (anonymised if you want, by email if you want). I can only provide generics at the moment.

Assuming your cart is written by a sane person, it will most likely keep the cart contents either in a cookie or in a session (either through the default PHP session handler or otherwise). In order to do what you have in mind, you’ll need to find a way to access the contents of this session, which you will most likely already have by now.

From there, I’m assuming each item in the cart has an ID. You can easily query the DB for the info you’d like, and allow the user to enter extra data by adding HTML fields (input[type=“text”] or textarea). Following that, save and redirect to a page of your liking. You can save the extra data in the same session, for simplicity. The best way to do it would be a session of the format:
[php]array(
array(“id” => itemID, “extra” => “extra data here”),
array(“id” => itemID, “extra” => “extra data here”),
array(“id” => itemID, “extra” => “extra data here”)
);[/php]

Which allows you to easily look items up in breadth (get all the item IDs by looping) and depth (array_search for an ID, and look up the extra parameter from there) rather than maintaining two lists.

If your cart system already uses models (MVC approach or similar), you’ll have no trouble loading items from the DB by ID. If it doesn’t, I’ll strongly recommend looking up a tutorial on models and to use them for abstraction. The large majority of your code as it stands seems to be more on function rather than form, however… and for simplicity, I’d recommend mimicking the style and layout of the code you’ll be extending.

Hello,

thanks for your answer. I know it is a very difficult description of the problem.
Whether the cart is written sane, I don’t know. I started PHP development in depth since 2 weeks now but am missing a lot of knowledge. I only managed to write the simple cart based on searching via Google. My cart is now working with $_SESSION variables.

After the selection I will indeed have to proceed to a new page running over the ID’s from the selection and create a new form again with all the fields from the database.

Your idea of the array is great, but how can I put this in a $_SESSION ?

I have no idea what are models / MVC approach :frowning: So I will need to look that up.

During the page lookups, I think it would be a good idea to save the data to a table too, just in case the webbrowser crashes or is closed by accident ? How would I achieve that ?

Please send me your e-mail address in a PB so I can provide the code I already have.

Greetings and thanks in advance,

Davy

Sponsor our Newsletter | Privacy Policy | Terms of Service