Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database.

Similar presentations


Presentation on theme: "PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database."— Presentation transcript:

1 PHP and SQL Server: Queries IST2101

2 Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database have been sent to everyone – Always use team webspace and SQL Server account for the project, not your personal ones! Wednesday’s class: Team discussion on Report 4

3 Labs We have already announced 6 required labs – HTML basics; PHP basics; IF/ELSE and Loop; HTML form; PHP and SQL Server: Connection; PHP and SQL Server: Queries (case 3a) – The first 6 exercises  5% lab exercise credits We will have several additional lab exercises and they are optional – The first one will be announced today – You can earn bonus points by finishing them – Bonus points might be used to curve the final grade Depends on how far you are from the curving margin Depends on how many extra labs you complete

4 What we have so far Using PHP to access and query the database and display results on webpage (week11-2) – http://my.up.ist.psu.edu/zuz22/query.php http://my.up.ist.psu.edu/zuz22/query.php IST2104

5 What we have so far Query the database with constraints (week11-3) – http://my.up.ist.psu.edu/zuz22/case2a.php http://my.up.ist.psu.edu/zuz22/case2a.php

6 What a cool website looks like Text box Checkboxes Dropdown lists Submit buttons

7 HTML Form Element Review: Text Fields Text fields are used when you want the user to type letters, numbers, etc. in a form IST2107

8 HTML Form Element Review: Submit Button When the user clicks the "Submit" button, the content of the form is sent to another file, which is defined by action attribute of the tag IST2108

9 HTML Form Element Review: Radio Buttons Radio Buttons are used when you want the user to select one of a limited number of choices IST2109 Pick a student (0-4)! 0 1 2 3 4 Value that will be passed to the process pageValue show on the page

10 HTML Form Element Review: Checkboxes Checkboxes are used when you want the user to select one or more options of a limited number of choices. IST21010 Pick a student (0-4)! 0 1 2 3 4

11 HTML Form Element Review: Dropdown lists Dropdown lists let the user choose from a set of given options. IST21011 Pick a student (0-4)! 0 1 2 3 4

12 Revisiting priceline.com Text box Checkboxes Dropdown lists Submit buttons

13 Today’s Topic: Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired information? 2.HTML form design – What form element(s) are most suitable for user input in this case? 3.Query processing and result display – How to query the database and display the results using PHP?

14 Case Study I want a website to show me the information of all projects which are assigned to one or more specific employees User input example: 1 - Mary Jacobs 5 - Heather Jones

15 Step 1: Query Generation Write SQL query to show the projects which are assigned to employees 1-Mary Jacobs and 5-Heather Jones

16 Step 1: Query Generation Write SQL query to show the projects which are assigned to employees 1-Mary Jacobs and 5-Heather Jones SELECT * FROM PROJECT WHERE ProjectID IN (SELECT ProjectID FROM ASSIGNMENT WHERE EmployeeNumber IN (1,5));

17 Step 2: HTML Form Design Is the following design appropriate? I want a website to show me the information of all projects which are assigned to one or more specific employees Problems: 1.Users may not know which employees are in the database 2.Users may not know what information is needed (employee number, or employee name, or both?)

18 Step 2: HTML Form Design Solution: When possible, give users a list of options to choose from Is the following design appropriate? I want a website to show me the information of all projects which are assigned to one or more specific employees Problem: Selection of more than one employee is not allowed.

19 Step 2: HTML Form Design Solution: Using checkboxes Is the following design appropriate? I want a website to show me the information of all projects which are assigned to one or more specific employees

20 Step 2: Code Specification IST21020 case4.php Retrieve the IDs and names of all employees from database Use the “while loop” to generate a checkbox for each employee Name of the array which stores the user’s choices Value that will be passed to the process page Value shown on the webpage

21 Step 3: Query Processing process_case4.php This is the SQL Query we wrote in Step 1. Employee numbers are obtained from user input

22 Case 4. Try it yourself Download the case4.php and process_case4.php from course website. Open case4.php and process_case4.php from NotePad++ and add your database information to both files IST21022 Input your own information

23 Case 4. Try it yourself (cont’d) Visit the php page to query your database – http://my.up.ist.psu.edu/YourPSUID/case4.php IST21023

24 In-class Exercise: Case 5 Create PHP webpages to show the information of all employees which are assigned to one or more specific projects – http://my.up.ist.psu.edu/zuz22/case5.php http://my.up.ist.psu.edu/zuz22/case5.php

25 Step 1: Query Generation Write SQL query to show the employees which are assigned to projects 1100-2010 Q3 Portfolio Analysis and 1200-2010 Q3 Tax Preparation Execute the query in SQL Management Studio to make sure you retrieve the desired result

26 Step 2: HTML Form Design Create case5.php in your webspace, copy from case4.php and modify it IST21026 Action to which PHP page?

27 Step 2: HTML Form Design (cont’d) Modify your case5.php IST21027 Modify this query to retrieve all projects instead of employees Modify these lines to display all the projects using checkboxes

28 Step 3: Query Processing Create process_case5.php, copy from process_case4.php and modify it IST21028 What ID should you use now? Put the SQL Query you wrote in Step 1 here. The IDs are obtained from user input.

29 Lab Exercise: Case 6 (Bonus Point) I want a website to show me the assignment information between all employees from one specific department and one or more specific projects I want a website to show me the assignment information between all employees from one specific department and one or more specific projects User input example: Department: Accounting Projects: 1100 2010 Q3 Portfolio Analysis 1200 2010 Q3 Tax Preparation Corresponding output:


Download ppt "PHP and SQL Server: Queries IST2101. Project Report 4 SQL Queries Due Sunday, 4/5 at 11:59pm Instructions on how to access team webspace and SQL database."

Similar presentations


Ads by Google