I am currently working on some code for a website that involves changing prices depending on what boxes are checked. A problem I am seeing with this is that there is no set formula for the increase or decrease of price. For example, if box A is checked the price equals 10, if box B is checked the price is 13, and if box C is checked the price equals 28. They are all just random. Will this just have to be hard coded in and what would a code look like for this?
Thanks!
Adding prices coding
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Adding prices coding
Write your application logic out in plain English.
Then code it.
Then code it.
Re: Adding prices coding
Never hardcode anything unless you absolutely have no other choice.
How the code works really depends on what you're doing with the data. Noone can say without knowing a lot more about what you're writing.
How the code works really depends on what you're doing with the data. Noone can say without knowing a lot more about what you're writing.
Re: Adding prices coding
This code is meant to display the price at the bottom of the page depending on how many boxes are checked. It helps the user of the site see how much money they are spending depending on how many boxes they have checked, and allows them to decide to change it before it is submitted.
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Adding prices coding
So are you just providing a sum of the values of the checkboxes?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Re: Adding prices coding
array_sum() might be of interest to you then.