So our college assignment involves a number of things right now, but I've currently hit a roadblock. I've managed to get my page to access the database I have for somethings...but its not displaying all the rows of the database. I'm not sure what I can do to remedy this.
The page looks like this: work so far
Here is my "index.php" coding:
<?php
try
{
$pdo = new PDO('mysql:host=localhost;dbname=--------', '-----------', '-------------');
$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 'includes/error.html.php';
exit();
}
try
{
$sql = 'SELECT title, description, duration, transportation, food, price, image, reservation FROM tours';
$result = $pdo->query($sql);
}
catch (PDOException $e)
{
$error = 'Error fetching page: ' . $e->getMessage();
include 'includes/error.html.php';
exit();
}
while ($row = $result->fetch())
{
$tours[] = array(
'title' => $row['title'],
'description' => $row['description'],
'duration' => $row['duration'],
'transportation' => $row['transportation'],
'food' => $row['food'],
'price' => $row['price'],
'image' => $row['image'],
'reservation' => $row['reservation']
);
}
include 'tours.html.php';
And here is my tours.html.php page:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Portland Historical Tour Options</title>
<meta name="description" content="Portland Historical Tours have offered three family run tours for decades: the Downtown Tour, the Growth Tour, and the Landmarks 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.html.php'; ?>
<?php include '../includes/navigation.inc.html.php'; ?>
<main>
<table>
<span id="caption">Compare Tour Options</span>
<tr>
<th id="tourname">Tour</th>
<th id="tourduration">Duration</th>
<th id="transportation">Transportation</th>
<th id="food">Food</th>
<th id="price">Price</th>
<th class="reserve">Reserve</th>
</tr>
<?php foreach ($tours as $tour): ?>
<tr>
<td headers="tourname"><?php echo $tour['title']; ?></td>
<td headers="tourduration"><?php echo $tour['duration']; ?></td>
<td headers="transportation"><?php echo $tour['transportation']; ?></td>
<td headers="food"><?php echo $tour['food']; ?></td>
<td headers="price"><?php echo $tour['price']; ?></td>
<td class="reserve"><?php echo $tour['reservation']; ?></td>
</tr>
</table>
<?php endforeach; ?>
<?php foreach ($tours as $tour): ?>
<h1><?php $tour['title']; ?></h1>
<img class="image" src="<?php $tour['image']; ?>" alt="Portland Downtown Tour" width="200" height="200">
<?php $tour['description']; ?>
<div><?php $tour['reservation']; ?>Reserve</div>
<br class="clearright">
<?php endforeach; ?>
</main>
<?php include '../includes/footer.inc.html.php'; ?>
</div>
</body>
</html>
Please keep in mind that I'm new to PHP, and this class is for people new to this form of coding. The instructor wants "simple" solutions" to the issues we face.
The database's table has 3 rows, one of which has links to images present. These are written in as "images/downtown.png". (This is just one example of course.)
I have tried to rename the links as "../images/downtown.png".
The index.php, and tours.html.php pages are in their own folder. There is a separate index.php page that is the homepage for the site. Images, "include" files (like header.inc.html.php) are located in this file.
</div>