showDetails.php
Source of showDetails.php
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>showDetails.php</title>
<style type = "text/css">
dt {
float: left;
width: 4em;
clear: left;
}
dd {
float: left;
width: 20em;
}
</style>
</head>
<body>
<?php
//connect
try {
$con= new PDO('mysql:host=localhost;dbname=dbName', "user", "pwd");
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//get most information for requested hero
$hero = "binary boy";
$query = <<<HERE
SELECT
*
FROM
heroMissionView
WHERE
hero = '$hero'
HERE;
print "<dl> \n";
$result = $con->query($query);
$result->setFetchMode(PDO::FETCH_ASSOC);
foreach ($result as $row){
foreach ($row as $field => $value){
print <<<HERE
<dt>$field</dt>
<dd>$value</dd>
HERE;
} // end field foreach
} // end row foreach
print " <dt>powers</dt> \n";
print " <dd> \n";
//create another query to grab the powers
$query = <<<HERE
SELECT
power
FROM
heroPowerView
WHERE hero = '$hero'
HERE;
//put powers in an unordered list
$result = $con->query($query);
print " <ul> \n";
foreach ($result as $row){
foreach ($row as $field => $value){
print " <li>$value</li> \n";
} // end foreach
} // end while loop
print " </ul> \n";
print "</dd> \n";
print "</dl> \n";
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
} // end try
?>
</body>
</html>