From the course: PHP for Web Designers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Calculating the order total

Calculating the order total - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Calculating the order total

Among it's many talents, PHP is capable of handling calculations from simple arithmetic to much more complex mathematics. The Order confirmation page in the Hansel & Petal site needs just some basic multiplication and addition. What we need to do is to add the cost here, and then to add a total at the end, and add a shipping charge if the total comes to less than $75. So let's get to work in the Order page. Go to the editing program. And then in order.php, let's create a variable to store the total. We'll put that at the top here, the end of the first block. Set total to zero and then in the loop in the table we need to find the cell that displays the price. There it is with a dollar sign. The dollar sign will be a literal dollar sign, it won't be part of the PHP. So the PHP block goes immediately after that. And inside there, what we need to do is to calculate the cost. So, the cost will be amount, that's the number of flowers selected, and it will be times. In PHP, we use the…

Contents