php - 如何将博客的标题和提取动态链接到它的大内容到 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>
解决方案
推荐阅读
- node.js - 请求的模块“@azure/arm-authorization”应为 CommonJS 类型
- python - AttributeError:“str”对象没有属性“add_artist”matplotlib
- python - Python Tkinter 帐户丢失时间
- git - Git 提交以 myname 的作者身份提交,并且 myname 在 20 分钟前提交。名称在 commit 中出现了两次。如何让它只出现一次?
- julia - 如何正确使用@constraintref?朱莉娅语言
- c# - 将 VBA 选择案例转换为 C#
- python - 如何使 NetworkX 图形可视化更具可读性?
- amazon-web-services - 如何通过 cloudformation 重新创建 lambda 函数?
- php - 将数组值与三元运算符结果连接起来
- html - Python:如何将我的 python 脚本嵌入到网页中