Page 1 of 1

Adding prices coding

Posted: Wed Jun 04, 2008 12:47 pm
by cow8boi8
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!

Re: Adding prices coding

Posted: Wed Jun 04, 2008 12:49 pm
by RobertGonzalez
Write your application logic out in plain English.

Then code it.

Re: Adding prices coding

Posted: Wed Jun 04, 2008 12:50 pm
by onion2k
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.

Re: Adding prices coding

Posted: Wed Jun 04, 2008 1:24 pm
by cow8boi8
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.

Re: Adding prices coding

Posted: Wed Jun 04, 2008 1:29 pm
by RobertGonzalez
So are you just providing a sum of the values of the checkboxes?

Re: Adding prices coding

Posted: Wed Jun 04, 2008 1:56 pm
by cow8boi8
Yes!

Re: Adding prices coding

Posted: Wed Jun 04, 2008 2:22 pm
by RobertGonzalez
array_sum() might be of interest to you then.