PHP Calculator

Soldato
Joined
30 Apr 2007
Posts
3,095
Location
Kent
Hi Guys,

I run a website for a guy that I know that owns his own bait rolling company. The more bait people order, the less it costs them - to avoid confusion, I've created a little 'calculator'. However, he's now changed his prices, and I can't get it to work.

The code I currently use is:

Code:
<?

$amount = $_POST['amount'];

$kilob="6";

$kiloa="5";

$ten="10";

$msg="standard message<br />";

if (!$amount || $amount<0) {

echo "Please enter a value that is greater than zero!";

}

else

if ($amount < $ten) {

$sum = $amount * $kilob;

echo "$msg";

echo "<center><b>For $amount Kg your estimated price is: £$sum</b></center>";

}

else

if ($amount >= $ten) {

$sum = $amount * $kiloa;

echo "$msg";

echo "<center><b>For $amount Kg your estimated price is: £$sum</b></center>";
}

else
echo "Error - Please try again";

?>

The prices he now has are:

Up to 50Kg = £5.50 per kilo
50kg - 100Kg = £5.00 per kilo
100Kg plus = £4.50 per kilo

If someone can help me out that be great - my code is probably really poor too, so any advice on that would be great!

Thanks in Advance
 
Hmm, I've got it working with this code:

Code:
<?
$amount = $_POST['amount'];

$limit1="50";
$limit2="100";

$price1="5.50";
$price2="5";
$price3="4.50";

$msg="message<Br /><Br />";

if (!$amount || $amount<0) {
echo "Please enter a value that is greater than zero!";
}

else
if ($amount < $limit1) {
$sum = $amount * $price1;
echo "$msg";
echo "<center><b>For $amount Kg your estimated price is: £$sum</b></center>";
}

else
if ($amount <= $limit2) {
$sum = $amount * $price2;
echo "$msg";
echo "<center><b>For $amount Kg your estimated price is: £$sum</b></center>";
}

else
if ($amount > $limit2) {
$sum = $amount * $price3;
echo "$msg";
echo "<center><b>For $amount Kg your estimated price is: £$sum</b></center>";
}

else
echo "Error - Please Try Again";
?>

How do I get it to show for example "5.50" instead of "5.5" ?

Thanks
 
Back
Top Bottom