Question

In: Computer Science

Part 2: Use MySQL Workbench to add a table to your database on the class server...

Part 2:

  1. Use MySQL Workbench to add a table to your database on the class server and name the table “Person”. Include these fields in the Person table:

Field Name

Description

Data Type

Sample Value

LoginID

User’s login name

varchar(10)

Bob

FirstName

User’s first name

varchar(50)

Bob

LastName

User’s last name

varchar(50)

Barker

picUrl

Filename of the user’s picture

varchar(50)

bob.gif

Bio

User’s biography

varchar(255)

Bob is the best!

LoginID should be the Primary Key of the table.

Add at least ten records to the Person table.

  1. Add a Persons page, named person.php. This page should display the contents of your Person table in an HTML table by using SQL to read records from the database table. Use linked styles to decorate the page background, all headers and table cell contents. E.g., font family, font size, color, etc. Place the .css file in an appropriate application subdirectory as in the class examples.

Solutions

Expert Solution

This demonstration is using MySQL Workbench.

1.Table Name :Person
create table Person(
LoginID varchar(10),
FirstName varchar(50),
LastName varchar(50),
PicUrl varchar(50),
Bio varchar(255),
Primary key (LoginID));

/*adding records to person table*/
insert into Person values ('ViratKohli','Virat','Kohli','Image1.jpg','Virat is the best ODI Player!');
insert into Person values ('MSDhoni','MS','Dhoni','Image2.jpg','Dhoni is the best Indian Captain!');
insert into Person values ('RSharma','Rohit','Sharma','Image3.jpg','Rohit is the best ODI Opener!');
insert into Person values ('RPonting','Rickey','Ponting','Image4.jpg','Rickey is the best Australian Captain!');
insert into Person values ('ShaneWarne','Shane','Warne','Image5.jpg','Shane is the best Spinner!');
insert into Person values ('MichBaven','Michel','Bevan','Image6.jpg','Michel is the best ODI finisher!');
insert into Person values ('KLRahul','KL','Rahul','Image7.jpg','KL is the best TWI Player!');
insert into Person values ('JamesBond','James','Bond','Image8.jpg','James is the best ODI Bowler!');
insert into Person values ('AjjuRahane','Ajinkya','Rahane','Image9.jpg','Ajinkya is the best Test Player!');
insert into Person values ('EionMorgan','Eion','Morgan','Image10.jpg','Eion is the best ODI Captain for England!');

/*selecting reocrds from Person table*/
select * from person;

Screen in MySQL Workbench :

*********************************************************

Person.php :

<?php

//database connection

$servername = "localhost";//server name

$username = "root";//username

$password = "";//password left blank

$database="personsDB";//database name

$conn = new mysqli($servername, $username, $password,$database);

?>

<!DOCTYPE html>

<html lang="en">

    <head>

        <!-- title for web page -->

        <title>Person Table</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1">

        <!-- link is used to refer t o external css -->

        <link href="person.css" rel="stylesheet">

    </head>

    <body>

    <table>

        <caption>Person Details</caption>

        <tr>

            <th>LoginID</th>

            <th>FirstName</th>

            <th>LastName</th>

            <th>PicUrl</th>

            <th>Bio</th>

        </tr>

        <?php

             //SQL query to get person table data

    $query = "select LoginID,FirstName,LastName,PicUrl,Bio from person;";

    if ($result = $conn->query($query)) {

    while ($row = $result->fetch_assoc()) {  

    $LoginID = $row["LoginID"];//get LoginID

    $FirstName = $row["FirstName"];//get FirstName

    $LastName = $row["LastName"];//get LastName

    $PicUrl = $row["PicUrl"];//get OicUrl

    $Bio = $row["Bio"];//get Bio

    ?>

    <tr>

        <td><?php echo $LoginID  ?></td>

        <td><?php echo $FirstName  ?></td>

        <td><?php echo $LastName  ?></td>

        <td><img src='<?php echo $PicUrl  ?>'/></td>

        <td><?php echo $Bio  ?></td>

    </tr>

    <?php

        }

     $result->free();

    }

    

        ?>

    </table>

    </body>

</html>

*****************************************

Person.css :

/* style rule for body */

body{

    background-color:lightblue;

}

/* style rule for table , td , th */

table,td,th,tr{

    border: 2px solid red;

    border-collapse: collapse;

}

/* style rule for caption */

caption{

    font-size: 20px;

    color: brown;

    font-weight: bolder;

}

/* style rule for alternate row */

tr:nth-last-of-type(odd){

    background-color:maroon ;

    color: white;

}

tr:nth-last-of-type(even){

    background-color:violet ;

    color: white;

}

/* style for img */

img{

    width: 50px;

    height: 50px;

}

=========================================

Output :

NOTE :All images are shown for demonstration purpose only.Make required changes.


Related Solutions

This refer to the “om” database (or Schema) that you will find in your MySQL Workbench...
This refer to the “om” database (or Schema) that you will find in your MySQL Workbench program if you have run the sample database install script. Please save all of your answers in one script (.sql) or type all your answers into Notepad++ and submit them as a single .sql file. Please test your SQL statements in Workbench 1.       Using an INNER JOIN, select the order_id, order_date, shipped_date, fname, and customer_phone from the orders and customers tables. The fname is a...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence”...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence” with the following attributes (columns): A field named “id” which has data type auto_increment, A field named “country_name” which has data type varchar(50), and A field named “independence_date” which has type “date.” After you create the table, run the following SQL command: INSERT INTO independence(country_name, independence_date) VALUE (‘United States’,’1776-07-04’) Submit a 1-page Microsoft Word document that shows the following: The SQL command you used...
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12....
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12. SELECT the trackid, name and filesize (as shown in the bytes column) for all tracks that have a file size less than 2000000 and a GenreId of 1 or a file size less than 2000000 and a Genreid of 2 -- 13. Add a sort to the query from number 12 to sort by GenreID; -- 14. List all columns from the customer table...
Design and implement a relational database application of your choice using MS Workbench on MySQL a)...
Design and implement a relational database application of your choice using MS Workbench on MySQL a) Declare two relations (tables) using the SQL DDL. To each relation name, add the last 4 digits of your Student-ID. Each relation (table) should have at least 4 attributes. Insert data to both relations (tables); (15%) b) Based on your expected use of the database, choose some of the attributes of each relation as your primary keys (indexes). To each Primary Key name, add...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that shows the table in 3rd Normal Form. Part two: Provide a summary of the steps you took to achieve 3rd Normal form. Include your rationale for new table creation, key selection and grouping of attributes. Table Details: The Anita Wooten Art Gallery wishes to maintain data on their customers, artists and paintings. They may have several paintings by each artist in the gallery at...
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE...
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE edu; Create a script which will create the tables listed below: STUDENT(STUDENT_ID, STUDENT_NAME, MAJOR_ID, DOB, PHONE_NUMBER) MAJOR(MAJOR_ID, MAJOR_NAME) ENROLLMENT(STUDENT_ID, COURSE_ID, GRADE) COURSE(COURSE_ID, COURSE_NAME) RESPONSIBILITY(FACULTY_ID, COURSE_ID) TEACHER(FACULTY_ID, DEPT_ID, TEACHER_NAME) DEPARTMENT(DEPT_ID, DEPARTMENT_NAME) Start the script with a series of DROP statements so that as you correct mistakes you will start fresh each time. To avoid referential integrity errors, the table drops should be in the opposite...
"How can I connect my hadoop database or mysql database server to my d3 visual?"
"How can I connect my hadoop database or mysql database server to my d3 visual?"
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,...
Use Workbench/Command Line to create the commands that will run the following queries/problem scenarios. Use MySQL...
Use Workbench/Command Line to create the commands that will run the following queries/problem scenarios. Use MySQL and the Colonial Adventure Tours database to complete the following exercises. 1. List the last name of each guide that does not live in Massachusetts (MA). 2. List the trip name of each trip that has the type Biking. 3. List the trip name of each trip that has the season Summer. 4. List the trip name of each trip that has the type...
Write a SQL script to add another table to your database. Include these fields in your...
Write a SQL script to add another table to your database. Include these fields in your Product table: Field Name Description Data Type Sample Value ProductID Product ID integer 5 ProductName Product Name varchar(50) candle Description Product Description varchar(255) Bee’s wax candle picUrl Filename of the product’s picture varchar(50) candle.gif Price Product Price decimal 10.99           ProductID should be the Primary Key. It is an auto-increment field.           The Price field stores prices to 7 significant digits and to 2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT