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!
Hi all I am adding some 'basic' code to a system that adds a shipping value based on the price to the total cart $total which will then return a $grand_total
My problem is that I am unsure if I am doing this correctly, if the total amount is less than 45 then 2.50 is added but if it is 45 and over 0 gets added, this is what I have so far but oit isn't passing a value through
/* Delivery Costs. */
$delivery_costs = "1.50";
$delivery_costs2 = "0.00";
/* Grand Total. */
$grand_total = $total + $delivery_costs;
//the less than or equal to removes one line of code
if ($total <= "45.00") {
echo "$grand_total = ($total + $delivery_costs)";
}
else {
echo "The grand total is: ".$grand_total;
}
I have tidied up your code for you, but the only problem was that you were using the print statement to display variables... This is fine except you have to use single quotes and not double ones. To save yourself worrying about silly things like this just use the echo statement instead, it does the same without the rubbish.
/* Delivery Costs. */
$delivery_costs = 1.50;
$delivery_costs2 = 0.00;
/* Grand Total. */
$grand_total = $total + $delivery_costs;
//the less than or equal to removes one line of code
if ($total <= "45.00") {
echo "$grand_total = ".$total + $delivery_costs;
}
else {
echo "The grand total is: ".$grand_total;
}
Last edited by m@ndio on Fri Jul 04, 2003 6:47 am, edited 1 time in total.