Forum Moderators: coopster
It should work like this:
When someone orders a 'blue' 'large' widget, use the price from the price table in the column for blue and row for large.
If they said 'yes' to "this-and-this-question": add up 10% to this price. Else display the original price.
If they said 'yes' to "this-and-this-question" And "that-and-that-question": add up 20% to the price and display the total price. Else display the previous price.
I just do not understand how to get started, which syntax to use to get the original price from the table. And then I get lost.
The value of large is present in a column called? Let's assume it is called 'size'. I am also assuming the table is actually called 'price'.
Select blue from price where size='large';
your query would be something like that. I am not sure if you need all the explanation of the Basics of extracting data from MySQL using PHP [webmasterworld.com]
>> If they said 'yes' to "this-and-this-question": add up 10% to this price. Else display the original price.
once you put the price into a variable, we'll call it $price, you need to compare it. With out a bunch of more specific info I can't give you the exact code. Let's assume your form element is called 'question1', that it's possible values are yes and no and also that it was posted to this script
if ($_POST['question1'] == 'yes') {
$price = $price + ($price * 0.1);
} >> If they said 'yes' to "this-and-this-question" And "that-and-that-question": add up 20% to the price and display the total price. Else display the previous price.
we can now add to our above code because there are 2 requirements. Let's call the second form element question2
if ($_POST['question1'] == 'yes') {
if ($_POST['question2'] == 'yes') {
$price = $price + ($price * 0.2);
} else {
$price = $price + ($price * 0.1);
}
} this assumes that if the answer to question2 is not 'yes' then you only add 10%
Thank you very much. Your answer will save me a lot of time.