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
dthomas31uk
Forum Newbie
Posts: 19 Joined: Mon Oct 13, 2008 8:14 am
Post
by dthomas31uk » Mon Oct 20, 2008 4:42 am
I have 3 option boxes
Code: Select all
echo 'Load from 14m3 - 20m3' . "<label><input type='radio' name='load' value='luton'</label>"."<BR>";
echo 'Load from 7m3 - 14m3'."<label><input type='radio' name='load' value='full_load'</label>"."<BR>";
echo 'Load from 1m3 - 7m3' . "<label><input type='radio' name='load' value='half_load'</label>"."<BR>";
And need to calculate totals based on one of the options selected. Trouble is I think my if statements are not written correctly. Can anyone advise here is the code that calcultes the option boxes from my database
Code: Select all
if ($load == 'full_load') {
$total = $row['full_price'];
}
if ($load == 'half_price') {
$total = $row['half_price'];
}
if ($load == 'luton') {
$total = $row['luton'];
}
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Mon Oct 20, 2008 4:48 am
You could use a switch:
Code: Select all
$load = $_POST['load'] //Depending on your form method
switch($load) {
case "full_load":
$total = $row['full_price'];
break;
case "half_price":
$total = $row['half_price'];
break;
case "luton":
$total = $row['luton'];
break;
}
dthomas31uk
Forum Newbie
Posts: 19 Joined: Mon Oct 13, 2008 8:14 am
Post
by dthomas31uk » Mon Oct 20, 2008 4:58 am
Hi papa. had it working when I had two option buttons like so
Code: Select all
if ($load == 'full_load') {
$total = $row['full_price'];
} else {
$total = $row['half_price'];
}
have tried your switch code, but it only calculates the 'half_price' , dont know why
aceconcepts
DevNet Resident
Posts: 1424 Joined: Mon Feb 06, 2006 11:26 am
Location: London
Post
by aceconcepts » Mon Oct 20, 2008 5:19 am
You haven't ended your input elements:
Change
Code: Select all
<input type='radio' name='load' value='half_load'
To
Code: Select all
<input type='radio' name='load' value='half_load' />
Forgot to mention, you need to do this to all of your radio elements.
dthomas31uk
Forum Newbie
Posts: 19 Joined: Mon Oct 13, 2008 8:14 am
Post
by dthomas31uk » Mon Oct 20, 2008 5:37 am
have got it working now Papa cheers. The problem was that I did not select my third option in my select query, thus it did not calculate. Thanks a lot
papa
Forum Regular
Posts: 958 Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm
Post
by papa » Mon Oct 20, 2008 5:38 am
No probs. Good it worked out for you!