index.php脚本不会加载?

时间:2014-03-19 12:37:37

标签: php database content-management-system

cms不会加载,它只会在index.php的名称下显示一个空白页面。在添加foreach循环之前它工作正常。我抬头看着互联网,我发现foreach循环没有任何问题。它突然不再起作用了。救命? :-) 下面是我目前使用的文件。

的index.php      

  include_once('includes/connection.php');
  include_once('includes/article.php');

  $article = New Article;
  $articles = $article->fetch_all();

  print_r($articles);
?>

  <html>
    <head>
      <title>Visuality dashboard</title>
      <link rel="stylesheet" type="text/css" href="assets/stylesheet.css">
    </head>

    <body>
      <div class="container">
        <a href="index.php" id="logo">CMS</a>
       <ol>
          <?php foreach ($articles as $article) { ?>
            <li>
              <a href="article.php?id=<?php echo $article ['article_id']; ?>">
                <?php echo $article['article_title']; ?>
              </a>
              - <small>
                posted <?php echo date('l jS, $article['article_timestamp']');?>
              </small>
            </li>

          <?php } ?>
      </ol>
    </div>
    </body>

    <footer>
    </footer>
  </html>

ARTICLE.PHP

    <?php

  class Article {
    public function fetch_all() {
      global $pdo;

      $query = $pdo->prepare("SELECT * FROM articles");
      $query->execute();

      return $query->fetchAll();
  }
}

?>

CONNECT.PHP

<?php

  try {
  $pdo = new PDO('mysql:host=localhost;dbname=cms', 'root', 'root');
} catch (PDOException $e) {
  exit('Database error.');
}

?>

1 个答案:

答案 0 :(得分:0)

更改以下内容:

<a href="article.php?id=<?php echo $article ['article_id']; ?>">

<a href="article.php?id=<?php echo $article['article_id']; ?>">

posted <?php echo date('l jS, $article['article_timestamp']');?>

posted <?php echo date('l jS', $article['article_timestamp']);?>