首页 > 解决方案 > 如何将博客的标题和提取动态链接到它的大内容到 PHP 和 mysql 数据库中的另一个页面

问题描述

这是我的 Index.php 代码,其中包含在我的主页 index.php 页面中显示的博客的每篇文章的标题、摘录和图像。我希望每篇文章的标题都有一个指向其大内容的链接,以显示到同一表数据库中的另一个页面。我不知道怎么弄明白。任何帮助将不胜感激。顺便说一句,我是一个绝对的初学者。

索引.php:

<?php
require_once 'includes/dbconfig.php';


try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password,  array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));

    $sql = 'SELECT  title, publish_date, extract, image


               FROM articles
              ORDER BY id';

    $q = $pdo->query($sql);
    $q->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    die("Could not connect to the database $dbname :" . $e->getMessage());
}
?>
<?php
echo $row['id'].
$row['title'].
$row['extract'];

?>">
<!DOCTYPE html>
<html>
    <head>
        <title>blog</title>
        <link href="css/bootstrap.min.css" rel="stylesheet"></a>
        <link rel="stylesheet" href="dist/css/chic.min.css">

    </head>
    <body>
      <div class="header">
        <h2>My Blog</h2>
        </div>


        <header>
           <nav>


              <ul>
                 <li><a href="index.php">Home</a></li>
                 <li><a href="includes/testing.php">Page Billet blog</a></li>
                 <li><a href="includes/check/index.php?login">Login</a></li>
                 <!-- <li></li> -->

              </ul>
           </nav>
        </header>

                    <?php while($row = $q->fetch()): ?>
                        //here is my update
                   <a href="includes/articles.php?id=<?php echo $row['id'].$row['content']; ?>
                      <?php $s=$row['image']; ?>
                      <div class="container">
                      <div class="row">
                        <div class="leftcolumn">
                          <div class="card">
                          <h1 class="title"> <?php echo htmlspecialchars($row['title']); ?> </h1>
                          <h5 class="publish_date">  <?php echo htmlspecialchars($row['publish_date']); ?> </h5>
                          <p class="extract">  <?php echo htmlspecialchars($row['extract']); ?> </p>
                          <div class="fakeimg"><?php echo '<img src="'.$s.'" issue displaying img >';?></div>
                      </div>
                      </div>




                    <?php endwhile; ?>




    </body>
</html>

这是articles.php:

<?php
require_once 'dbconfig.php';

?>
<!DOCTYPE html>
<html>
    <head>
        <title>blog</title>
        <link href="css/bootstrap.min.css" rel="stylesheet">
        <link rel="stylesheet" href="../dist/css/articles.min.css">
    </head>
    <body>
      <div class="header">
        <h2>My Blog</h2>
        </div>






              <?php  $id = $_GET['id']; ?>


    </body>
</html>

标签: phpsqlpdophpmyadmin

解决方案


推荐阅读