/* Check if the database connection is established. If not, exit the program. */
if (!$db) {
echo "Could not connect to the database";
exit();
}
?>
// Define variables and assign their default values
$mode = ""; // default value for the switch statement
$parameterValues = null; // default values named parameters
$pageTitle = ""; // define a title for each output
$columns = array(); // define an array of column labels for a table header
try {
if (isset($_GET['mode'])) {
$mode = $_GET['mode'];
}
switch ($mode) {
case "members": // display a list of members
// 1. define SQL statement
$sql = "SELECT `firstName`, `lastName` FROM `members` order by `lastName`";
// 2. Define values for named parameters. There are no parameters in this SQL statement. Use the default.
// 3. Fetch result set
$resultSet = getAll($sql, $db, $parameterValues);
// 4. Display result
$pageTitle = "List of Members";
$columns = array("First Name", "Last Name"); // we will use a two-column table to display members
displayResultSet($pageTitle, $resultSet, $columns);
break;
case "movies": // display a list of movies, based on the selected genre
// 1. define SQL statement
/* Note: We use two key/value pairs:
mode - identifies the switch case
genre - movie type
If genre=all then display all the movies.
If genre=Drama then display Drams type movies.
Need two different SQL statements.
We can use an...