【发布时间】:2021-09-01 17:19:30
【问题描述】:
我正在开发一个博客项目(学习课程),其中显示了相关的火车和 cmets 的账单。它使用 GET 参数。
我做了教授要求的所有改进,除了我必须在 url 上加载带有参数的博客。下面有一个屏幕截图,它显示未定义的索引,这很好,但我不知道如何使用参数加载它:
我尝试使用 include,但我没有其他文件要加载我在同一页面中进行了所有改进,并且也使用了空的 fonction(),但是在我不知道如何制作之后(我是初学者)。
我不是在问答案,但是如果您有任何提示可以帮助处理,或者如果它太复杂,请给我一个解释! (对不起,如果我的英语不好,我不是本地人)
代码:
<?php
include('connexion.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<title>Blog</title>
</head>
<body>
<h1>Mon super Blog !</h1>
<p>Derniers billets du blog : </p>
<!-- NEWS -->
<div class="news">
<?php
$recuperation_titre_du_billets_et_contenu = $bdd->query("SELECT Id,Titre,Contenu,DATE_FORMAT(Date_creation,'%d/%m/%Y à %H:%i') AS date_affiché FROM billets LIMIT 0,4");
while($données = $recuperation_titre_du_billets_et_contenu->fetch())
{
echo "<h3>".htmlspecialchars($données['Titre'])." le ".htmlspecialchars($données['date_affiché'])."</h3>";
?>
<p>
<?php echo htmlspecialchars($données['Contenu']);
?>
<a href="commentaires.php?Id_billet=<? echo $données['Id']?>&page_commentaire=1">Commentaires</a>
</p>
<?php
}
$recuperation_titre_du_billets_et_contenu->closeCursor();
?>
</div>
<!-- FIN NEWS -->
<!-- NEWS2 -->
<div class="news2">
<?php
$billetsdelapage2 = $bdd->prepare("SELECT Id,Titre,Contenu,DATE_FORMAT(Date_creation,'%d/%m/%Y à %H:%i') AS date_affiché FROM billets LIMIT 4,4");
$billetsdelapage2->execute(array($_GET['page']));
if(isset($_GET['page']) == 2)
{
while($data = $billetsdelapage2->fetch())
{
echo "<h3>".htmlspecialchars($data['Titre'])." le ".htmlspecialchars($data['date_affiché'])."</h3>";
?>
<p>
<?php echo htmlspecialchars($data['Contenu']);
?>
<a href="commentaires.php?Id_billet=<? echo $data['Id'];?>">Commentaires</a>
<?php
}
?>
<style>
.news
{
display:none;
}
</style>
</p>
<?
}
$billetsdelapage2->closeCursor();
?>
</div>
<!-- FIN NEWS2 -->
<!-- NEWS3 -->
<div class="news3">
<?php
$billetsdelapage3 = $bdd->prepare("SELECT Id,Titre,Contenu,DATE_FORMAT(Date_creation,'%d/%m/%Y à %H:%i') AS date_affiché FROM billets LIMIT 8,12");
$billetsdelapage3->execute(array($_GET['page']));
if(isset($_GET['page']) AND ($_GET['page'] != 2 ))
{
while($data = $billetsdelapage3->fetch())
{
echo "<h3>".htmlspecialchars($data['Titre'])." le ".htmlspecialchars($data['date_affiché'])."</h3>";
?>
<p>
<?php echo htmlspecialchars($data['Contenu']);
?>
<a href="commentaires.php?Id_billet=<? echo $data['Id']?>">Commentaires</a>
<?
}
?>
<style>
.news
{
display:none;
}
.news2{
display:none;
}
</style>
</p>
<?
}
$billetsdelapage3->closeCursor();
?>
</div>
<!-- FIN NEWS3 -->
</div>
<div class="pagination">
<!-- Petite erreur qui sera rectifié plus tard vis à vis des numéros de page ! -->
<a href="index.php">1</a>
<a href="index.php?page=2">2</a>
<a href="index.php?page=3">3</a>
</div>
</body>
</html>
【问题讨论】:
-
请出示代码
-
我把代码放在上面了。