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 - PHP Tutorial
From the course: PHP for Web Designers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
(Locked)
Getting form input sent by the POST method4m 48s
-
Retrieving values from a URL's query string4m 8s
-
(Locked)
Challenge: Plan the order form2m 28s
-
(Locked)
Solution: Plan the order form4m 42s
-
(Locked)
Finding and extracting a substring7m 38s
-
(Locked)
Organizing the form data into arrays7m 15s
-
(Locked)
Using a loop to build a table for the data4m 42s
-
(Locked)
Controlling which rows are displayed7m 45s
-
(Locked)
Creating a custom function to extract part of a file name7m 43s
-
(Locked)
Calculating the order total6m 34s
-
(Locked)
Using PHP sessions to preserve data3m 14s
-
(Locked)
Storing data in session variables7m 33s
-
(Locked)
Ending the PHP session and deleting the data5m 37s
-
(Locked)
-
-
-