Adding prices coding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cow8boi8
Forum Newbie
Posts: 5
Joined: Wed Jun 04, 2008 12:33 pm

Adding prices coding

Post 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!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Adding prices coding

Post by RobertGonzalez »

Write your application logic out in plain English.

Then code it.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Adding prices coding

Post 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.
cow8boi8
Forum Newbie
Posts: 5
Joined: Wed Jun 04, 2008 12:33 pm

Re: Adding prices coding

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Adding prices coding

Post by RobertGonzalez »

So are you just providing a sum of the values of the checkboxes?
cow8boi8
Forum Newbie
Posts: 5
Joined: Wed Jun 04, 2008 12:33 pm

Re: Adding prices coding

Post by cow8boi8 »

Yes!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: Adding prices coding

Post by RobertGonzalez »

array_sum() might be of interest to you then.
Post Reply