In: Computer Science
Part 2:
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.
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.