Question

In: Computer Science

Create a web interface that has a backend database that takes a value of one table...

Create a web interface that has a backend database that takes a value of one table and displays it match from another table.

Create a web interface, that has a backend database, the database contains two tables, one table contains courses in one curriculum, while the other table in the database has corresponding classes from another curriculum. A user should be able to pick a course from the curriculum, and the matching course from the other table should populate on screen.

Windows operating system. HTML, SQL, PHP. WAMP

Solutions

Expert Solution

Database (SQL table data) ---please run the below commands in your database

Database create command
CREATE DATABASE myDB

Tables create command
CREATE TABLE `mydb`.`courses` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `course` VARCHAR(250) NOT NULL , `createdTime` TIMESTAMP NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
CREATE TABLE `mydb`.`classes` ( `id` INT(11) NOT NULL AUTO_INCREMENT , `classId` INT(11) NOT NULL , `name` VARCHAR(250) NOT NULL , `createdTime` TIMESTAMP NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;

Sample coures data command
INSERT INTO `courses` (`id`, `course`, `createdTime`) VALUES (NULL, 'HTML', CURRENT_TIMESTAMP), (NULL, 'CSS', CURRENT_TIMESTAMP);
INSERT INTO `courses` (`id`, `course`, `createdTime`) VALUES (NULL, 'JAVASCRIPT', CURRENT_TIMESTAMP), (NULL, 'PHP', CURRENT_TIMESTAMP);

Sample classes data command
INSERT INTO `classes` (`id`, `classId`, `name`, `createdTime`) VALUES (NULL, '1', 'Introduction', CURRENT_TIMESTAMP), (NULL, '1', 'HTML Tags', CURRENT_TIMESTAMP);
INSERT INTO `classes` (`id`, `classId`, `name`, `createdTime`) VALUES (NULL, '1', 'Attributes', CURRENT_TIMESTAMP), (NULL, '1', 'HTML Forms', CURRENT_TIMESTAMP);
INSERT INTO `classes` (`id`, `classId`, `name`, `createdTime`) VALUES (NULL, '2', 'Basics', CURRENT_TIMESTAMP), (NULL, '2', 'Style Types', CURRENT_TIMESTAMP);

task.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
$coursesData='';
$classesData='';
//Get Courses
$sql = "SELECT id, course FROM courses";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
       $coursesData .= "<option value='".$row['id']."'>".$row['course']."</option>";
}
}
//Get Classes
$sql1 = "SELECT name FROM classes where classId=1";
$result1 = mysqli_query($conn, $sql1);
if (mysqli_num_rows($result1) > 0) {
   $index=1;
while($row1 = mysqli_fetch_assoc($result1)) {
       $classesData .= "<tr>
                           <td>".$index++."</td>
                           <td>".$row1['name']."</td>
                       </tr>";
                          
}
}
else
{
   $classesData='NO data available';
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Courses</title>
<style>
table {
width:100%;
border-collapse: collapse;
}

table, th, td {
   margin-top:10px;
   padding:5px;
border: 1px solid black;
}
</style>
</head>
<body>
   <div>
       <label>Select Course</label>
       <select>
           <?php echo $coursesData ?>
       </select>
   </div>
   <div>
       <table>
           <thead>
               <tr>
                   <th>S.No</th>
                   <th>Classes</th>
               </tr>  
           </thead>
           <tbody>
               <?php echo $classesData ?>
           </tbody>
       </table>
   </div>
</body>

</html>

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "myDB";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
$coursesData='';
$classesData='';
//Get Courses
$sql = "SELECT id, course FROM courses";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
       $coursesData .= "<option value='".$row['id']."'>".$row['course']."</option>";
}
}
//Get Classes
$sql1 = "SELECT name FROM classes where classId=1";
$result1 = mysqli_query($conn, $sql1);
if (mysqli_num_rows($result1) > 0) {
   $index=1;
while($row1 = mysqli_fetch_assoc($result1)) {
       $classesData .= "<tr>
                           <td>".$index++."</td>
                           <td>".$row1['name']."</td>
                       </tr>";
                          
}
}
else
{
   $classesData='NO data available';
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Courses</title>
<style>
table {
width:100%;
border-collapse: collapse;
}

table, th, td {
   margin-top:10px;
   padding:5px;
border: 1px solid black;
}
</style>
</head>
<body>
   <div>
       <label>Select Course</label>
       <select>
           <?php echo $coursesData ?>
       </select>
   </div>
   <div>
       <table>
           <thead>
               <tr>
                   <th>S.No</th>
                   <th>Classes</th>
               </tr>  
           </thead>
           <tbody>
               <?php echo $classesData ?>
           </tbody>
       </table>
   </div>
</body>

</html>


Related Solutions

DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class...
DROP DATABASE class;CREATE DATABASE class;Use class;drop table if exists Class;drop table if exists Student;CREATE TABLE Class (CIN int PRIMARY KEY, FirstName varchar(255), LastName varchar(255), Gender varchar(1), EyeColor varchar(50), HairColor varchar(50), HeightInches int,CurrentGrade varchar(1));CREATE TABLE Student (SSN int PRIMARY KEY,FirstName varchar(255),LastName varchar(255), Age int,BirthMonth varchar(255),HeightInches int,Address varchar(255),City varchar(255),PhoneNumber varchar(12),Email varchar(255),FavColor varchar(255),FavNumber int);INSERT INTO Class VALUES(1, "David", "San", "M", "BRN", "BLK", 72, "-");INSERT INTO Class VALUES(2, "Jeff", "Gonzales", "M", "BRN", "BLK", 68, "B");INSERT INTO Class VALUES(3, "Anna", "Grayson", "F", "BRN", "BRN", 62,...
How do I create a backup and restore strategy for a web site and the database...
How do I create a backup and restore strategy for a web site and the database for the site?
Information on the following Database: create database Sales_Co use Sales_Co create table Vendor (v_code integer, v_name...
Information on the following Database: create database Sales_Co use Sales_Co create table Vendor (v_code integer, v_name varchar(35) not null, v_contact varchar(15) not null, v_areacode char(3) not null, v_phone char(8) not null, v_state char(2) not null, v_order char(1) not null, primary key (v_code)); create table product (p_code varchar(10) constraint product_p_code_pk primary key, p_descript varchar(35) not null, p_indate datetime not null, p_qoh integer not null, p_min integer not null, p_price numeric (8,2) not null, p_discount numeric (4,2) not null, v_code integer, constraint...
2 -​Create the code to generate a web page that contains a table. The table should...
2 -​Create the code to generate a web page that contains a table. The table should have 4 ​columns and 4 rows. Each cell should be 100 pixels wide by 100 pixels high. The border ​should be 2 ​pixels.
Given is a Python program that connects to a sqlite database and has one table called...
Given is a Python program that connects to a sqlite database and has one table called writers with two columnns: name - the name of a writer num - the number of works the writer has written The writers table originally has the following data: name, num Jane Austen,6 Charles Dickens,20 Ernest Hemingway,9 Jack Kerouac,22 F. Scott Fitzgerald,8 Mary Shelley,7 Charlotte Bronte,5 Mark Twain,11 Agatha Christie,73 Ian Flemming,14 J.K. Rowling,14 Stephen King,54 Oscar Wilde,1 Update the Python program to ask...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the relational schema created in a mini case MC5 in chapter 3. Use insert into statements to insert no fewer than 2 and no more than 10 records per table.
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that...
In Java Create an interface Create an interface Printing, which have a method getPageNumber () that return page number of any printing. Create an abstract class named Novel that implements Printing. Include a String field for the novel's title and a double field for the novel price. Within the class, include a constructor that requires the novel title, and add two get methods--one that returns the title and one that returns the price. Include an abstract method named setPrice().. Create...
Create a table on one page of your site that has at least one colspan or...
Create a table on one page of your site that has at least one colspan or rowspan. Style it with at least three selectors in your stylesheet. You can use element, class and/or ID. (Note: do not use deprecated HTML attributes - use CSS!) Add at least two font stacks to your website including one web font from Google Fonts (Links to an external site.) Use padding, margin, and border at least once each in your stylesheet.
Create a simple web page with two(2) AJAX interactions with a mySQL Database AJAX 1 should...
Create a simple web page with two(2) AJAX interactions with a mySQL Database AJAX 1 should return HTML content for use on the page AJAX 2 should return JSON content for use on the page Use a JS library, such as jQuery, to ensure the AJAX works on all browsers
Using SQL create a new database called school_app. Create a student table with fields id (auto...
Using SQL create a new database called school_app. Create a student table with fields id (auto increment), first_name, last_name. Create a course table with fields id (auto increment), course code (such as ITC or MTH), and course number (such as 100 or 295). Note that the relationship between student and course is many-to-many (n:m). Create a join table called student_course that implements the n:m relationship with fields id (auto increment), student_id, course_id, and grade (which has values 0, 1, 2,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT