Nedanstående filer finns i denna katalogen. Klicka på en fil för att visa dess innehåll.
adventure03/
common.php config.php img/ room.php source.php stylesheet.css template.php
<?php // =========================================================================================== // // room.php // // Description: Read information of a room from the database and display it as HTML. // // // Author: Mikael Roos // // ------------------------------------------------------------------------------------------- // // Error handling on/off // error_reporting(E_ALL | E_STRICT); $debug = ""; $debugEnable = FALSE; // TRUE to enable debugging, FALSE to not print out debug information // ------------------------------------------------------------------------------------------- // // Take care of GET variables, and validate them // // Get the id of the room $idRoom = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); if($idRoom === FALSE || $idRoom === NULL || $idRoom < 0) die("Felaktig _GET värde."); // ---------------------------------------------------------------------------- // // Connect to the database server // require_once('config.php'); $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE); if (mysqli_connect_error()) { echo "Connect failed: ".mysqli_connect_error()."<br>"; exit(); } // ---------------------------------------------------------------------------- // // Prepare and perform a SELECT query // $idRoom = $mysqli->real_escape_string($idRoom); $query = <<<EOD SELECT * FROM Rum WHERE id = '{$idRoom}' ; EOD; $res = $mysqli->query($query) or die("Could not query database, query =<br/><pre>{$query}</pre><br/>{$mysqli->error}"); // ---------------------------------------------------------------------------- // // Show the results of the query // $row = $res->fetch_object(); $titleRoom = $row->namn; $descriptionRoom = $row->beskrivning; $res->close(); // ---------------------------------------------------------------------------- // // Prepare and perform a SELECT query // $query = <<<EOD SELECT * FROM Rumkoppling WHERE id_Rum1 = '{$idRoom}' ; EOD; $res = $mysqli->query($query) or die("Could not query database, query =<br/><pre>{$query}</pre><br/>{$mysqli->error}"); // ---------------------------------------------------------------------------- // // Show the results of the query // $connectionsRoom = ""; while($row = $res->fetch_object()) { $connectionsRoom .= "<a href='{$_SERVER['PHP_SELF']}?id={$row->id_Rum2}'>{$row->namn}</a> "; } $res->close(); // ---------------------------------------------------------------------------- // // Close the connection to the database // $mysqli->close(); // ------------------------------------------------------------------------------------------- // // The content of the page // $html = <<<EOD <div class='wrapper'> <h1>Äventyrsspel</h1> <h2>{$titleRoom}</h2> <div class='gamearea'> <!-- - Testing 3 different ways of including an external svg-image into html. - read more: http://w3schools.com/svg/svg_inhtml.asp - - <object type="image/svg+xml" data="img/bakgrund.svg" /> - <embed type="image/svg+xml" src="img/bakgrund.svg" width="720" height="480" /> - <iframe src="img/bakgrund.svg" width="720" height="480" frameborder="0"></iframe> - --> <embed type="image/svg+xml" src="img/bakgrund.svg" width="720" height="480" /> </div> <!-- gamearea --> <div class='description'> <h4>Beskrivning:</h4> <p class='description'>{$descriptionRoom}</p> </div> <!-- description --> <div class='action'> <h4>Riktningar:</h4> <p class='action'>{$connectionsRoom}</p> </div> <!-- actions --> </div> <!-- wrapper --> EOD; // ------------------------------------------------------------------------------------------- // // Create and print out the html-page // require_once('common.php'); $title = "Äventyrsspel"; $charset = "iso-8859-1"; $language = "sv"; $stylesheet = ""; $html = <<< EOD <?xml version="1.0" encoding="{$charset}" ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="{$language}" lang="{$language}"> <head> <meta http-equiv="Content-Type" content="text/html; {$charset};" /> <title>{$title}</title> <style type="text/css">{$stylesheet}</style> <link rel='stylesheet' href='stylesheet.css' type='text/css' media='screen' /> </head> <body> {$header} {$html} {$footer} </body> </html> EOD; header("Content-Type: application/xhtml+xml; charset={$charset}"); echo $html; exit; ?>
. ..: © Mikael Roos, 2009