php and sql server: queries ist2101. steps to design php pages to answer user queries 1.query...
TRANSCRIPT
![Page 1: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/1.jpg)
IST210 1
PHP and SQL Server: Queries
![Page 2: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/2.jpg)
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?
![Page 3: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/3.jpg)
Example: Case 4
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
![Page 4: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/4.jpg)
Step 1: Query Generation
• Write SQL query to show the projects which are assigned to employees 1-Mary Jacobs and 5-Heather Jones
![Page 5: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/5.jpg)
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 PROJECTWHERE ProjectID IN
(SELECT ProjectIDFROM ASSIGNMENTWHERE EmployeeNumber IN (1,5));
![Page 6: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/6.jpg)
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 database2. Users may not know what information is needed (employee
number, or employee name, or both?)
![Page 7: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/7.jpg)
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.
![Page 8: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/8.jpg)
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
![Page 9: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/9.jpg)
IST210 9
Step 2: Code Specificationcase4.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
![Page 10: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/10.jpg)
Step 3: Query Processing process_case4.php
This is the SQL Query we wrote in Step 1.
Employee numbers are obtained from user input
![Page 11: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/11.jpg)
IST210 11
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
Input your own information
![Page 12: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/12.jpg)
IST210 12
Case 4. Try it yourself (cont’d)
Visit the php page to query your database– http://my.up.ist.psu.edu/YourPSUID/case4.php
![Page 13: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/13.jpg)
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
![Page 14: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/14.jpg)
Step 1: Query Generation
• Write SQL query to show the employees which are assigned to projects with ID 2 and 3.
• Execute the query in SQL Management Studio to make sure you retrieve the desired result
![Page 15: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/15.jpg)
IST210 15
Step 2: HTML Form Design
• Create case5.php in your webspace, copy from case4.php and modify it
Action to which PHP page?
![Page 16: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/16.jpg)
IST210 16
Step 2: HTML Form Design (cont’d)
• Modify your case5.phpModify this query to retrieve all projects instead of employees
Modify these lines to display all the projects using checkboxes
![Page 17: PHP and SQL Server: Queries IST2101. Steps to Design PHP Pages to Answer User Queries 1.Query generation – What SQL query do we need to retrieve the desired](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5697bfc91a28abf838ca8d7d/html5/thumbnails/17.jpg)
IST210 17
Step 3: Query Processing
• Create process_case5.php, copy from process_case4.php and modify it
What ID should you use now?
Put the SQL Query you wrote in Step 1 here.
The IDs are obtained from user input.