dp198879 2018-02-27 01:04
浏览 75

需要帮助html表并获取php echo来访问数据库表

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>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭