Question: I have been able to record the last and first names of the actors, the number of films they starred in, but I'm not able

I have been able to record the last and first names ofI have been able to record the last and first names of the actors, the number of films they starred in, but I'm not able to record/output the actual movies they starred in with the other two. That's all I have left for this task. Below I will provide my code as of right now, so please help me with recording and output the actual movies the actors starred in. Thank you.

View Films

//Connect to database

$server = "localhost";

$user = "root";

$pw = "";

$db = "sakila";

$connect = mysqli_connect($server, $user, $pw, $db);

if( !$connect)

{

die("ERROR: Cannot connect to database $db on server $server

using user name $user (".mysqli_connect_errno().

", ".mysqli_connect_error().")");

}

//SQL query to select film information.

$outerQuery = "SELECT concat(a.last_name, ', ',a.first_name) as Actor, count(fa.actor_id) as Num_Films

FROM actor as a

INNER JOIN film_actor fa ON a.actor_id = fa.actor_id

GROUP BY fa.actor_id

ORDER BY a.last_name;";

//Execute query

$result = mysqli_query($connect, $outerQuery);

//Throw error if query failed or no results returned, otherwise display results.

if (!$result) {

die("Could not successfully run query ($outerQuery) from $db: " .

mysqli_error($connect) );

}

if (mysqli_num_rows($result) == 0) {

print("No records found with query $outerQuery");

}

else {

print("

List of Films

Back to Actor's Portal

");

//Displays information for each film

$first = true;

print("

");

while ($row = mysqli_fetch_assoc($result))

{

if ($first) {

$first = false;

print("

");

foreach($row as $key=>$value) {

print("

");

}

}

print("

");

foreach($row as $key=>$value) {

print("

");

}

}

}

mysqli_close($connect); // close the connection

?>

Task 1 1) Create a file titled writeActors.php. This file should query your database to find all the movies that each actor starred in. You need to write to a text file a record for each actor. The record should contain the first and last name of the actor, the number of films they starred in, and a list of the films. You should also write this information to an HTML table with 3 columns. Use the format shown below. (note that Julia Fawcett actually starred in 15 films, below is simply to demonstrate the file format). Both the html table and the text file should be sorted by actor last name. Last Name,First Name:number of films:filmTitle,, filmTitle2iIn For example: Fawcett, Julia:2:Berets Agent, Boiled Dares
$key
$value

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!