Presentation is loading. Please wait.

Presentation is loading. Please wait.

In Class Programming BIS1523 – Lecture 11.

Similar presentations


Presentation on theme: "In Class Programming BIS1523 – Lecture 11."— Presentation transcript:

1 In Class Programming BIS1523 – Lecture 11

2 Supply and Demand Today we are going to write a program to forecast quantity and price of a commodity. We are going to use CSS, data validation, single form design, ifs and loops to accomplish this.

3 Input The starting input form is divided into three sections: header, #description, #io. The three inputs are named: years, quant, and price Rather than being an .html document, this is a .php document, the calculate button calls this form, not a separate one.

4 PHP Outline When the user clicks the submit button, the submit value gets sent to the program. If the web site is visted by another means, the submit value is not set. For our PHP, we need to do an outline that looks like: If (empty($_POST[‘submit’])) { display the input page } else { do the PHP to input, calculate, and display the output }

5 Submit Detection We’ll start with an if statement just after the header, and test it. Next, rather than having it print “button not clicked”, let’s have it print the entire HTML for the input. Copy the HTML into the if statement, and place it inside a print command

6 Output Sections Next, we need to print out the HTML for the output section that doesn’t include any calculations. We have a description and io section Our calculations and output will go between the start and end tags for the io section

7 Input & Loop We use assignment statements to read in the three inputs.
We will use a for loop to print out the table.

8 Calculations For each year, we need to calculate a new quantity and price. We don’t need separate variables, we can just use the existing $quant and $price variables. The output is unformatted, and hard to read, but we can look at it to see that the calculations are being done correctly.

9 Adding a Table To put our output into a table, we need to output the <table>, <tr>, <th> and <td> tags in the appropriate place. (Both start and end tags).

10 Formatting the Table Next, we need to add CSS to format the table.
We include borders for table, td, and th, and the collapse attribute We change the background color of the header row And finally set an alternating color for every odd row

11 Data Validation The last step is to do some data validation. We want to check to make sure out inputs are numeric, and in range. We can include a span tag to give the error messages an ID, so we can style them with CSS making them more noticeable.

12 Flag Variable In order to prevent our output from being printed if there is an error, we’ll add a flag variable called $okay. We start it at “true”, and set it “false” if any errors are found in the input. Then, we put our calculate and output section inside an if statement that only runs if $okay is still TRUE.


Download ppt "In Class Programming BIS1523 – Lecture 11."

Similar presentations


Ads by Google