DeX Posted May 28, 2010 Share Posted May 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/203228-how-would-i-allow-the-user-to-edit-calculations-on-database-entries/ Share on other sites More sharing options...
jdavidbakr Posted May 28, 2010 Share Posted May 28, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203228-how-would-i-allow-the-user-to-edit-calculations-on-database-entries/#findComment-1064797 Share on other sites More sharing options...
DeX Posted May 28, 2010 Author Share Posted May 28, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/203228-how-would-i-allow-the-user-to-edit-calculations-on-database-entries/#findComment-1064810 Share on other sites More sharing options...
jdavidbakr Posted May 28, 2010 Share Posted May 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203228-how-would-i-allow-the-user-to-edit-calculations-on-database-entries/#findComment-1064813 Share on other sites More sharing options...
ignace Posted May 29, 2010 Share Posted May 29, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203228-how-would-i-allow-the-user-to-edit-calculations-on-database-entries/#findComment-1064950 Share on other sites More sharing options...
DeX Posted May 31, 2010 Author Share Posted May 31, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/203228-how-would-i-allow-the-user-to-edit-calculations-on-database-entries/#findComment-1065756 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.