0

Hello I would like to send an email with php code. I have the following script calculation that works:

<script type="text/javascript"> 
window.onload = function () {
    var total_of_order= <?php echo $order_total ?>;
    var extra_costs= 38;
    var total = Math.ceil(parseInt(total_of_order) - extra_costs);
    $('calculateTotal').innerHTML = total;
    } 
 </script>

<div id="calculateTotal"></div>

How can I code this to pure php? Like?

<?php echo $extra_costs; $extra_costs= "38";?>
<?php echo $order_total ?>
<?php echo $total = Math.ceil(parseInt(order_total) - extra_costs);?>

As you can see I''m the worst coder, could someone help me?

dfasf

1
  • <?php $order_total = 1111; $extra_costs = 38; $total = ceil($order_total) - $extra_costs; mail('[email protected]', 'blah', 'your total is '.$total); ?> just a starting point to send emails... Commented Jan 6, 2012 at 14:07

4 Answers 4

1

Use the ceil function, without Math. prefix. Also, since you're doing your calculations in PHP, you can directly output the result in the <div>, without any JavaScript.

<div id="calculateTotal">
<?php
    $order_total = ...; //Defined previously, not included in your question
    $extra_costs = 38;
    echo ceil($order_total -  $extra_costs);
?>
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for this answer. But accually it now shows -38... Als if I put a number instead of $order_total it works. But that another problem ;) thanx again everybody
0

Just remove the Math.

<?php echo $extra_costs; $extra_costs= "38";?>
<?php echo $order_total ?>
<?php echo ceil(order_total - extra_costs);?>

Comments

0
<?php

$extra_costs = 38;
$total = ceil($order_total - $extra_costs);

?>

<script type="text/javascript">
    $('calculateTotal').innerHTML = '<?php=$total?>';
</script>

Comments

0
<?php  

$extra_costs= 38;

$total = ceil($order_total) - $extra_costs;

?>

<div id="calculateTotal"><?php echo $total ?></div>

2 Comments

Why are you assigning a string to $extra_costs when it is an integer?
@scartag You also have too much parentheses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.