Jump to content

How would I allow the user to edit calculations on database entries?


Recommended Posts

Say I have a client who wants to do quotes for a building. They offer 2 building sizes with the following requirements (example) for materials:

1. Building A requires 5 2x4 and a window.

2. Building B requires 7 2x4 and 3 windows.

 

That's all good, I can put the relative prices for each material in the database and there's an equation to figure out which building requires how many of each material, that's fine. But how could I build this so that the client can go in afterwards and change it so Building B requires 8 2x4? How about if he now wants to offer doors as well for his buildings?

 

Right now I get the required quantities of each material through a series of calculations and then I add/multiply what's needed to get all materials for the building and the total cost. That's all done in the PHP code. How can I make it editable by a client who doesn't know code?

Instead of hard-coding your constants for your calculations, build a database that your php code uses to pull those values.  Then you can create an interface so that the end user can modify those values which in turn will change the results of your calculations.

 

You can alternatively have an interface that sets those values in session variables, if you don't need them to persist beyond the current session.  Have your code start by checking for the existence of the session variables and setting them to default values if they are not set, then update those session variables when the user changes the values through your interface.

Instead of hard-coding your constants for your calculations, build a database that your php code uses to pull those values.  Then you can create an interface so that the end user can modify those values which in turn will change the results of your calculations.

 

You can alternatively have an interface that sets those values in session variables, if you don't need them to persist beyond the current session.  Have your code start by checking for the existence of the session variables and setting them to default values if they are not set, then update those session variables when the user changes the values through your interface.

What if the calculation itself changes? What if now they want to multiply all costs by 2? Or instead of the number of 2x4 being equal to the length of the building, now the quantity will be something like (length * 2) / 3?

Instead of hard-coding your constants for your calculations, build a database that your php code uses to pull those values.  Then you can create an interface so that the end user can modify those values which in turn will change the results of your calculations.

 

You can alternatively have an interface that sets those values in session variables, if you don't need them to persist beyond the current session.  Have your code start by checking for the existence of the session variables and setting them to default values if they are not set, then update those session variables when the user changes the values through your interface.

What if the calculation itself changes? What if now they want to multiply all costs by 2? Or instead of the number of 2x4 being equal to the length of the building, now the quantity will be something like (length * 2) / 3?

 

Heh, well, that's the fun part - you get to figure out everything that the user will want to change and give them some access to it in an interface that you build.  Turning all those constants into variables is the easy part - building an interface for the user that makes it easy for them to change is why you get paid the big bucks  ;D

What is 2x4? Is this a product (in a Mathematical sense) and therefor 8? Or is this the name of a material? If it is a material, then:

 

Building A requires 5 2x4 and 1 window

Building B requires 7 2x4 and 3 windows

 

building (id, name)

material (id, name)

building_requires_material (building_id, material_id, quantity)

 

building (1, 'A')

material (1, '2x4'), (2, 'window');

building_requires_material (1, 1, 5) // Building A requires 5 2x4

building_requires_material (1, 2, 1) // Building A requires 1 window

..

 

Building C requires 5 2x4, 3 windows, 1 door

 

building_requires_material (3, 1, 5) // Building C requires 5 2x4

building_requires_material (3, 2, 3) // Building C requires 3 windows

building_requires_material (3, 3, 1) // Building C requires 1 door

What is 2x4? Is this a product (in a Mathematical sense) and therefor 8? Or is this the name of a material? If it is a material, then:

 

Building A requires 5 2x4 and 1 window

Building B requires 7 2x4 and 3 windows

 

building (id, name)

material (id, name)

building_requires_material (building_id, material_id, quantity)

 

building (1, 'A')

material (1, '2x4'), (2, 'window');

building_requires_material (1, 1, 5) // Building A requires 5 2x4

building_requires_material (1, 2, 1) // Building A requires 1 window

..

 

Building C requires 5 2x4, 3 windows, 1 door

 

building_requires_material (3, 1, 5) // Building C requires 5 2x4

building_requires_material (3, 2, 3) // Building C requires 3 windows

building_requires_material (3, 3, 1) // Building C requires 1 door

 

Very interesting way of doing this, thank you! And yes, 2x4 is a product, it's the width/depth measurements of a piece of lumber, pronounced two by four.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.