Skip to content
Snippets Groups Projects
Commit e1f0a234 authored by Benjamin Wells's avatar Benjamin Wells
Browse files

Finishing Lab 4

parent 66915a6e
Branches
No related merge requests found
Pipeline #28 skipped
<?php
// connect to the database
require('includes/db_connect.php');
require('includes/db_connect.php')
// include the header HTML
include('templates/header.html');
// include the navigation HTML
include('templates/navigation.html');
// get the value of the page parameter from the URL
// if no parameter detected...
// Code to detect whether index.php has been requested without query string
// If no page parameter detected...
if (!isset($_GET['page'])) {
$page_id = 'home'; // display home page
$id = 'home'; // display home page
} else {
$page_id = $_GET['page']; // else requested page
$id = $_GET['page']; // else requested page
}
switch ($page_id) {
case 'home' :
// Switch statement to decide content of page will go here.
// Regardless of which "view" is displayed, the variable $content will
switch ($id) {
case 'home' :
include 'views/home.php';
break;
case 'record' :
......@@ -28,10 +34,8 @@ default :
include 'views/404.php';
}
mysqli_close($link);
include('templates/footer.html');
include('templates/header.html');
include('templates/footer.html')
?>
?>
\ No newline at end of file
Live Demo
---------
This app can be viewed at:
http://doc.gold.ac.uk/~ma301bw/dnw/
\ No newline at end of file
http://doc.gold.ac.uk/~ma301bw/dnw/test_app/index.php
\ No newline at end of file
......@@ -4,4 +4,5 @@
<meta charset="UTF-8">
<title>Record Store</title>
</head>
<body>
\ No newline at end of file
<body>
<h1> Hello People </h1>
\ No newline at end of file
No preview for this file type
<?php
// connect to the database
require('includes/db_connect.php');
// include the header HTML
include('templates/header.html');
//include footer HTML
include('templates/footer.html');
// include the navigation HTML
include('templates/naviation.html');
// Code to detect whether index.php has been requested without query string
// If no page parameter detected...
......@@ -8,37 +20,25 @@ if (!isset($_GET['page'])) {
$id = $_GET['page']; // else requested page
}
$content = '';
// Switch statement to decide content of page will go here.
// Regardless of which "view" is displayed, the variable $content will
switch ($id) {
case 'home' :
include 'views/home.php';
break;
case 'page_2' :
include 'views/page_2.php';
break;
default :
include 'views/404.php';
case 'home' :
include 'views/home.php';
break;
case 'record' :
include 'views/record.php';
break;
case 'artist' :
include 'views/artist.php';
break;
default :
include 'views/404.php';
}
?>
<!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="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Test Application</title>
</head>
<body>
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="index.php?page=page_2">Page 2</a></li>
</ul>
<?php
// Display content for requested view.
echo $content;
mysqli_close($link);
include('templates/footer.html')
?>
</body>
</html>
<?php
$content .= '<h1>Sorry, page can not be found</h1>';
echo("Error 404: Page not found.");
?>
<?php
$content .= '<h1>Hello world!</h1>';
$content .= '<p>If you\'re reading this, it means you have successfully launched the <b>test app</b>.</p>'
echo("Home page");
?>
<?php
// create variable for content HTML
$content = "<h1>Records</h1>";
// fetch records as a result set
$sql = "SELECT title, genre, price FROM record";
$result = mysqli_query($link, $sql);
// check query returned a result
if ($result === false) {
echo mysqli_error($link);
} else {
$content .= "<table border='1'><tbody>";
// fetch associative array
while ($row = mysqli_fetch_assoc($result)) {
$content .= "<tr>";
$content .= "<td>".$row['title']."</td>";
$content .= "<td>".$row['genre']."</td>";
$content .= "<td>".$row['price']."</td>";
$content .= "</tr>";
}
$content .= "</tbody></table>";
// free result set
mysqli_free_result($result);
}
// output the content HTML
echo $content;
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment