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 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.
//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("
| $key | ");
|---|
| $value | ");
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
