Hi, so I’m new to PHP, and I’m taking a college class on it. However the instructor is not particularly helpful with his instructions on the assignment, and tends to give vague answers on how to find the solutions to issues we have.
Here is the basic problem. I have a database, and 2 seperate php pages. One is “index.php”. The other is “home.html.php”.
My problem, is the picture that I provided. I’ve tried coding this a few different ways, but for the life of me I am hung up on how to resolve the problem I’m facing. And since the instructor isn’t being helpful, I need someone to actually give me a helping hand in resolving this problem.
index.php: Supposed to connect to my xampp database, and pull rows from a certain table in the database.
<?php
try
{
$pdo = new PDO('mysql:host=localhost;dbname=seanropp_pht_db', 'seanropp_pht_user', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch (PDOException $e)
{
$error = 'Unable to connect to the database server.';
include 'home/error.html.php';
exit();
}
try
{
$sql = 'SELECT title, description, image FROM content';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching page: ' . $e->getMessage();
include 'home/error.html.php';
exit();
}
while ($row = $result->fetch())
{
$content[] = array(
'title' => $row['title'],
'description' => $row['description'],
'image' => $row['image'],
);
}
include 'home/home.html.php';
home.html.php: HTML page witht he “header”, “body”, “main”, etc. elements in it. PHP coding in here is the problem.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Portland Historical Tours</title>
<meta name="description" content="Portland Historical Tours has offered three Portland Tour options for over 33 years: the Downtown Tour, the Landmarks Tour and the Growth Tour.">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href=project.css>
<link href='https://fonts.googleapis.com/css?family=Cinzel' rel='stylesheet' type='text/css'>
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div id="wrapper">
<?php include 'includes/header.inc.php'; ?>
<?php include 'includes/navigation.inc.php'; ?>
<main>
<?php
foreach ($content as $contents): ?>
<?php
echo "<img src=" . "$contents" . "width='850' height='389'>";
echo "<h1>" . "$contents" . "</h1>";
echo "<p>" . "$contents" . "</p>";
?>
<!-- TEMPORARY Block out, use for referance, may need to delete later
<a href="tours.php"><img src="images/downtown.png" alt="Portland Historical Tours" width="850" height="389"></a>
<h1>How did we get started?</h1>
<p>
We have such a passion for the city we live in. For over 33 years we have offered tours for Portland visitors and residents alike through our family business. Having family in Portland since the early 1900's has allowed us to build tours out of insight over 100 years. We are confident you will love any of our Portland tours with the help of our generous guides. We offer three tours: the Downtown, the Growth, and the Landmarks tour. Our favorites are the Downtown and Landmarks but with Portland's current growth we are selling out our Growth tours.<br><br>We hope to meet you soon! Let us know if you have any questions by visiting the <a href="contact.html">Contact page.</a><br><br>Thank you!
</p>
-->
<!--
<a href="tours.html"><img src="images/downtowntour.png" alt="Portland Historical Downtown Tour" width="850" height="481"></a>
<div id="source"><p>(City of Portland Archives)</p></div>
<a href="tours.html"><img src="images/growthtour.png" alt="Portland Historical Growth Tour" width="850" height="481"></a>
<div id="source"><p>(City of Portland Archives)</p></div>
<a href="tours.html"><img src="images/landmarkstour.png" alt="Portland Historical Landmarks Tour" width="850" height="481"></a>
<div id="source"><p>(City of Portland Archives)</p></div>
-->
<?php endforeach; ?>
</main>
<?php include 'includes/footer.inc.php'; ?>
</div>
</body>
</html>