Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1.Create a table called “tblActor”. The tblActor should have the following field

ID: 3851873 • Letter: 1

Question

1.Create a table called “tblActor”. The tblActor should have the following fields (name, description, dob, country, image).Populate the table “tblActor” with information about your favorite four actors. Write a PHP code that read the data from the “tblActor” table, and generate a JSON response similar to the following format.

{"actors":[{"name":"Brad Pitt","description":"Brad Pitt is an American actor and film producer. He has received a Golden Globe Award, a Screen Actors Guild Award, and three Academy Award nominations in acting categories","dob":"December 18, 1963","country":"United States","image":" http:\ ors.com\brad.jpg"},{"name":"Tom Cruise","description":"Tom Cruise, is an American film actor and producer. He has been nominated for three Academy Awards and has won three Golden Globe Awards.","dob":"July 3, 1962","country":"United States","image":"http:\Actors.com\tom.jpg"},{"name":"Angelina Jolie","description":"Angelina Jolie is an American actress, film director, screenwriter, and author. She has received an Academy Award, two Screen Actors Guild Awards, and three Golden Globe Awards.","dob":"December 18, 1963","country":"United States","image":" http:\Actors.com\angelina.jpg"}]}

Note: You can use the https://jsonformatter.curiousconcept.com/   website to validate the above JSON response.

Name the PHP file “ViewAllActors.php”. Create a table called “tblTempActor”. The tblTempActor should have the following fields (name, description, dob, country, image).Write a PHP code called “ParseJSONToDB.php”. The “ParseJSONToDB.php” should call the “ViewAllActors.php” web service. Then it should parse the JSON response that will get from “ViewAllActors.php”, in addition, The “ParseJSONToDB.php” should also save the JSON parsed data into the “tblTempActor” table.

Explanation / Answer

Here is step by step solution (tested on wampserver with php version 5.5.12)

Step -1 Create tblActor table in mysql here is query for that:

CREATE TABLE IF NOT EXISTS `tblactor` (
`name` varchar(30) NOT NULL,
`description` varchar(1000) NOT NULL,
`dob` varchar(30) NOT NULL,
`country` varchar(30) NOT NULL,
`image` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Step 2- Fill records in table tblActor following is query:

INSERT INTO `tblactor` (`name`, `description`, `dob`, `country`, `image`) VALUES
('Brad Pitt', 'Brad Pitt is an American actor and film producer. He has received a Golden Globe Award, a Screen Actors Guild Award, and three Academy Award nominations in acting categories', 'December 18, 1963', 'United States', 'http:\\tors.com\brad.jpg'),
('Tom Cruise', 'Tom Cruise, is an American film actor and producer. He has been nominated for three Academy Awards and has won three Golden Globe Awards.', 'July 3, 1962', 'United States', 'http:\\Actors.com\tom.jpg'),
('Angelina Jolie', 'Angelina Jolie is an American actress, film director, screenwriter, and author. She has received an Academy Award, two Screen Actors Guild Awards, and three Golden Globe Awards.', 'December 18, 1963', 'United States', 'http:\\Actors.com\angelina.jpg');

step3: Create table tblTempActor here is query for that:

CREATE TABLE IF NOT EXISTS `tbltempactor` (
`name` varchar(30) NOT NULL,
`description` varchar(1000) NOT NULL,
`dob` varchar(30) NOT NULL,
`country` varchar(30) NOT NULL,
`image` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Step 4- here is code for viewAllActor.php

<?php
$host='localhost'; //replace your creadentials
$uname='root';
$pwd='';
$db="test";

$con=mysqli_connect($host,$uname,$pwd) or die("connection failed");
mysqli_select_db($con,$db) or die("db selection failed");
$sql = "select * from tblActor";
$result = mysqli_query($con,$sql);
$json = array();


if(mysqli_num_rows($result)){
while($row=mysqli_fetch_assoc($result)){
$json['actors'][]=$row;
}
}
mysqli_close($con);
echo json_encode($json);
?>

Step - 5 Here is code for ParseJSONToDB.php

<?php
$host='localhost';
$uname='root';
$pwd='';
$db="test";
$result;
$con=mysqli_connect($host,$uname,$pwd) or die("connection failed");
mysqli_select_db($con,$db) or die("db selection failed");


$jsondata = file_get_contents('http://localhost:8081/viewAllActors.php'); //call to viewAllActors.php remember to change your localhost address properly


$data = json_decode($jsondata, true);

foreach ($data as $row) {
foreach($row as $cell)
{
$sql = "INSERT INTO `test`.`tbltempactor` (`name`, `description`, `dob`, `country`, `image`) VALUES ('".$cell{"name"}."', '".$cell{"description"}."','".$cell{"dob"}."','".$cell{"country"}."','".mysqli_real_escape_string($con,$cell{"image"})."')";
$result =mysqli_query($con,$sql);
}
}

if($result) //this is to check if everything is fine with all records or not
echo "success";
else
echo "Unable to insert";

?>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote