Presentation is loading. Please wait.

Presentation is loading. Please wait.

In-Class Program: Sales System

Similar presentations


Presentation on theme: "In-Class Program: Sales System"— Presentation transcript:

1 In-Class Program: Sales System
BIS1523 – Lecture 16

2 Program Overview Todays project will consist of three pages:
One allows the user to order some quantity of products One shows the summary of that order One shows a summary of all orders places The program will use 2 external files: Products.txt lists all of the products available Prices.txt lists the prices for those products The files are set up so that the product on row X matches the price on row X

3 Order Page The order page consists of a bunch of text inputs, each with a corresponding product name, and price.

4 Results Page The results page prints out a summary for a single order

5 Report Page The report page simply lists total number of orders, total revenue spent, and average. To collect this data, we’ll need to log each report into a third file called log.txt

6 Columns We start with some simple un-styled HTML for our three columns on the input page: In order to line up the columns, we will give these headings an ID, and style them with inline-block, and a width. Inline-block specifies that these elements should be all on the same line, they don’t start their own line We’ll use the SPAN tag to give each column a class

7 Columns HTML CSS Results:

8 Loading Data To load the files into arrays, we use the file() function
We step through each element of the array, and print out a textarea, and the name and price from the array. For now we use a placeholder for the input textbox of some x’s We need to use the same SPAN classes for the columns to line up. Notice we also have to escape the quotes in them, since we are printing them with PHP

9 Resulting HTML Here are the results:

10 Quantity Input Next, we need to replace the X’s with an input that allows the user to type in a quantity. Each input needs to have a unique name. What we can do is use the loop variable $i, and name each one QTY1, QTY2, etc. The HTML produced looks like: We place that inside our SPAN tags….

11 QTY Results:

12 Results Page For the results, we are going to add an additional Column: So we add an additional SPAN, and CSS to match

13 Columns Much like the input page, we want to print out several columns of data. We will start by loading the files into arrays, and printing them all out.

14 Finding Quantity Now, we have a number of different qty variables we sent through our POST. Each has a unique number. PHP uses double quotes to say “do variable substitution here”, so we can use this format: To retrieve the quantity. Each time through the loop, the $qty variable will get set with the value of qty0, qty1, qty2, qt3, etc…..

15 Example

16 Skipping Unordered Items
If we want to only print out lines that the user ordered, we use an if statement, and check to verify $qty is bigger than 0.

17 Totalling Price Next, we add in the math to calculate the total per line, and the overall total price

18 Log File In order to calculate the summary, we need to write the total of each purchase into a file. If we don’t concatenate a PHP_EOL character, the new numbers are stuck together all on one line. So, we do that concatenation, and use FILE_APPEND to stick each new value on the file. The resulting file has one number per line:

19 Summary For the summary, we read the list of files, total them up inside a loop, and use that total to calculate an average


Download ppt "In-Class Program: Sales System"

Similar presentations


Ads by Google