Please select the first character of the last name:
__OUT_STRING;
}
elseif ($lnamef != '') {
// Show all customers with the specified first char of their last names.
echo <<<__OUT_STRING
Please click the customer link to see brief information of the customer.
__OUT_STRING;
$query = <<<__QUERY
SELECT DISTINCT customer_id, first_name, last_name,
IF(active = 0, 'inactive', 'active')
FROM customer
WHERE UPPER(SUBSTRING(last_name, 1, 1)) = ?
__QUERY;
if ($stmt = $mysqli->prepare($query)) {
$stmt->bind_param('s', $lnamef);
$stmt->execute();
$stmt->bind_result($cid, $fname, $lname, $active);
while ($stmt->fetch()) {
// Assume no special HTML characters
echo "- ".
"$fname $lname: $active
\n";
}
$stmt->close();
}
echo <<<__OUT_STRING
__OUT_STRING;
}
else { // cid <> ''. Show customer information.
// Check whether customer id exists in the database
$query = <<<__QUERY
SELECT DISTINCT C.first_name, C.last_name, COUNT(*) AS count
FROM customer C INNER JOIN rental R ON (c.customer_id = r.customer_id)
INNER JOIN inventory i ON (r.inventory_id = i.inventory_id)
INNER JOIN film f ON (i.film_id = f.film_id)
WHERE c.customer_id = ?
GROUP BY C.customer_id, C.first_name, C.last_name
__QUERY;
if ($stmt = $mysqli->prepare($query)) {
$stmt->bind_param('s', $cid);
$stmt->execute();
$stmt->bind_result($fname, $lname, $numFilms);
$hasResult = $stmt->fetch();
$stmt->free_result();
$stmt->close();
}
if (!$hasResult) {
echo <<<__NO_RESULT
Sorry, the id $cid is not in the database.
__NO_RESULT;
}
else {
echo <<<__OUT_STRING
Number of films rented by customer $fname $lname ($cid): $numFilms.
__OUT_STRING;
}
}
?>