"; if ($stmt = $mysqli->prepare($query)) { $stmt->bind_param('i', $customer_id); $stmt->execute(); $stmt->bind_result($film_id, $title); while ($stmt->fetch()) { // Assume no special HTML character echo "
  • $title (id: #$film_id): ". "similar films
  • \n"; } $stmt->close(); } echo ""; } elseif ($film_id != '') { $query = <<<__QUERY SELECT DISTINCT f.title, c.name from film AS f INNER JOIN film_category fc ON (f.film_id = fc.film_id) INNER JOIN category AS c ON (fc.category_id = c.category_id) WHERE fc.film_id = ? __QUERY; if ($stmt = $mysqli->prepare($query)) { $stmt->bind_param('i', $film_id); $stmt->execute(); $stmt->bind_result($film_title, $category); $stmt->fetch(); // Assume no special HTML character $stmt->close(); } echo "The film $film_title (id #$film_id) has the following similar films in the same category of $category:\n"; echo "
      "; $query = <<<__QUERY SELECT DISTINCT f.film_id, f.title, COUNT(fa1.actor_id) AS count FROM film AS f INNER JOIN film_actor AS fa1 ON (f.film_id = fa1.film_id) INNER JOIN film_actor AS fa2 ON (fa1.actor_id = fa2.actor_id AND f.film_id <> fa2.film_id) INNER JOIN film_category AS fc1 ON (f.film_id = fc1.film_id) INNER JOIN film_category AS fc2 ON (fa2.film_id = fc2.film_id AND fc1.category_id = fc2.category_id) WHERE fa2.film_id = ? GROUP BY f.film_id, f.title ORDER BY count DESC LIMIT 20; __QUERY; if ($stmt = $mysqli->prepare($query)) { $stmt->bind_param('i', $film_id); $stmt->execute(); $stmt->bind_result($film_id, $title, $actorCount); while ($stmt->fetch()) { // Assume no special HTML character echo "
    1. ($title id: (#$film_id): number of common actors -> $actorCount.
    2. \n"; } $stmt->close(); } } else { echo "Please specify a customer_id in your URL by adding the query string \"?cid=1\" at the end of the URL."; echo "You may replace 1 by any customer_id in the query string."; } ?>