Use the
assignment description.pdfas your guide for this assignment. The pdf is what you will be referencing the entire time. So read that if you have any questions.
For this assignment you will need to have some
SQL,
PHP,
HTML, and
JavaScriptknowledge. There might possibly be other coding skills referenced in the pdf that I might have forgot to mention here that you'll need to know.
(1) Assignment description and-or files needed/Assignment description.pdf 1 For this assignment you will be combining client-side techniques (JavaScript) and server-side scripting to display dynamic content. You need to know how to use key-value pairs to send a request to a server, reading key-value pairs into server-side variables, using a switch statement to perform a particular task based on the user input, and sending HTTP requests using promises. __________________________________________________________________________ 1. Create a folder named assignment7 in the htdocs folder. (I created this for you) 2. Using the movieApi.php file as a guide, create a php script to fetch the following data from the uww database: a) Select subject, number, sectionId, instructor, and displayTime of all the courses taught in a selected classroom b) Select subject, number, title, description, and maxcredits of all the courses based on a selected subject Save it as courseApi.php in assignment7 folder. Hint: use a switch statement similar to the one in movieApi.php file that includes at least three cases: one to display course information, one to display schedule information, and the default case. 3. Place a copy of the pdo_connect.php file in assignment7 folder. Make sure the database name in pdo_connect.php file is 'uww' since you are going to use tables in uww database. 2 4. Test your courseApi.php file. If you use a switch statement as in movieApi.php file, then the following link should display an empty array: http://localhost/assignment10/courseApi.php The following link should display an array of JSON objects containing information about classes scheduled to be taught in MG0115: http://localhost/assignment7/courseApi.php?type=schedule&location=MG0115 (you should be familiar with the purpose and format of any URL like the above. It is sending two key=value pairs to the server. Design the courseApi.php script to read those key=value pairs and use them to create the appropriate response.) 3 The following link should display an array of JSON objects containing information about COMPSCI courses: http://localhost/assignment7/courseApi.php?type=courses&subject=COMPSCI 6. Save the following as an HTML file: Schedule of Classes p, table {margin-left: 50px;} .hrule { border-top: 1px solid #000} .listItem { padding: 6px;}
Course Information
Display subject, number, title, description, and maxcredits of all the courses based on the selected subject:
4
Subject:
Subject |
Number |
Title |
Description |
Credits |
--Select subject -- |
Course Schedule
Display subject, number, sectionId, instructor, and displayTime of all the courses taught in the selected classroom:
Location:
5
Subject |
Number |
Section |
Instructor |
Time |
--Select location -- |
/* Add JavaScript code */ 6 7. Open the HTML file using any web browser. When a subject is selected from the first drop-down menu, the onchange event handler should invoke the function displayCourseInfo( ) function to fetch data from your database and display an appropriate list. Use the JavaScript code embedded in the movies.html as a guide to add a function called displayCourseInfo( ) to the above HTML file. The purpose of the displayCourseInfo( ) is to read the selected subject from the drop-down menu, fetch a matching set of courses from the database, and then display it. For example, if 'COMPSCI' is chosen from the drop-down menu, then it should produce an output similar to the following: 7 When a location is selected from the second drop-down menu, the onchange event handler should invoke the function displaySubjectList( ) function to fetch data from your database and display an appropriate list. Use the JavaScript code embedded in the movies.html as a guide to add a function called displaySubjectList( ) to the above HTML file. The purpose of the displaySubjectList( ) is to read the selected location from the drop-down menu, fetch a matching set of schedules from the database, and then display it. For example, if 'MG115' is chosen from the drop-down menu, then it should produce an output similar to the following: 8 Note: Since the output format for the two evnt handlers is different, you will have to use the prepareHTMLContent( ) method in movieApi.php file as a guide to add two different functions to the JavaScript code in the HTML file to prepare the appropriate output in each case. How to Submit this back to me Submit both HTML and courseApi.php files, as a zip file back to me. (1) Assignment description and-or files needed/movieApi.php $type); } // Execute SQL statement and obtain data $response = getAllRecords($sql, $db, $parameterValues); } break; case 'members' : // Define SQL statement $sql = "SELECT * FROM `members`"; // This SQL statement does not use any parameters. Use the default $parameterValues array. $response = getAllRecords($sql, $db, $parameterValues); break; default : $response = array(); break; } // end switch /* $response is an array of matching records ( array of associative arrays). The server response must be a string so we have to convert this array into a string with a format that is easy to convert to an array of Javascript objects. We use the json_encode() method to convert the $response into a string using a format which can easily be converted into an array of JavaScript objects called JSON objects. */ echo json_encode($response); function getAllRecords($sql, $db, $values = null){ /* Input values: 1. SQL statement that includes 'named' parameters 2. Database connection 3. (Optional) Values for 'named' parameters, if there are any 'named' parameters in the SQL statement Output: Array of matching result records. Each element in the array is an associative array. */ // prepare SQL statement $stm = $db->prepare($sql); // execute SQL statement $stm->execute($values); // fetch all records $result = $stm->fetchAll(PDO::FETCH_ASSOC); // return the result set return $result; } (1) Assignment description and-or files needed/movies.html Online Movie Store Filter movies by genre: All Action Adventure Animation Comedy Drama Romance TitleYearType (1) Assignment description and-or files needed/uww/uww/courses.sql SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; START TRANSACTION; SET time_zone = "+00:00"; -- -- Database: `uww` -- -- -------------------------------------------------------- -- -- Table structure for table `courses` -- CREATE TABLE `courses` ( `id` int(11) NOT NULL, `subject` varchar(30) CHARACTER SET latin1 NOT NULL, `number` varchar(20) CHARACTER SET latin1 NOT NULL, `title` varchar(200) CHARACTER SET latin1 NOT NULL, `description` text CHARACTER SET latin1 DEFAULT NULL, `mincredits` double NOT NULL DEFAULT 0, `maxcredits` double NOT NULL DEFAULT 0, `prereq` varchar(200) CHARACTER SET latin1 NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Dumping data for table `courses` -- INSERT INTO `courses` (`id`, `subject`, `number`, `title`, `description`, `mincredits`, `maxcredits`, `prereq`) VALUES (746, 'COMPSCI', '162', 'COMPUTER APPLICATIONS', ' A thorough introduction to commonly used computer applications, covering word processing, spreadsheets, data storage and retrieval, and presentation software. Students will learn the vocabulary of computing, the concepts of computing and problem solving, and how computer applications can be applied to a wide range of problems.
COREQ: MATH 139 OR MATH 140 OR MATH 142 OR WAIVER', 3, 3, ''), (747, 'COMPSCI', '271', 'ASSEMBLY PROGRAMMING', ' This course covers the use of an assembly language based on the RISC processor architecture including writing, linking, and executing a program. Also covered are number systems, instructions for arithmetic and logical operations, memory access, loops, declaring variables, interrupts, machine language, segments, stacks, procedure writing, and file handling.
PREREQ: COMPSCI 172 OR COMPSCI 174', 3, 3, ' COMPSCI 172 OR COMPSCI 174'), (748, 'COMPSCI', '412', 'COMPUTER ORGANIZATION AND SYSTEM PROGRAMMING', ' Introduction to organization of modern digital computers - understanding the various components of a computer and their interrelationships. Study of systems programming in C/Linux.
PREREQ: