我正在做一個博客專案(學習課程),該專案顯示火車的票據和相關評論。它是用GET引數作業的。
我做了教授要求的所有改進,除了一個我必須在URL上用引數加載博客的地方。下面有一個截圖,它顯示了未定義的索引,而且很好,但我不知道如何用引數加載它。
我試著用include,但我沒有其他檔案可以加載,我在同一個頁面做了所有的改進,也用了空的fonction(),但之后我不知道怎么做(我是初學者)。
我不是在問答案,但如果你有任何提示可以幫助我處理,或者如果它太復雜,請給我一個解釋!
如果我的英語不好,請原諒。(如果我的英語不好,我不是本地人,我很抱歉。
代碼:
。<?php
include('connexion.php');
?>。
<! DOCTYPE html>
<html lang="en">
<head>/span>
<meta charset="UTF-8">/span>
< meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=devicewidth, initial-scale=1. 0">
<link rel=" stylesheet" href="css/style。 css">
<title>Blog</title>/span>
</head>/span>
<body>
<h1>Mon super Blog !</h1>
<p>Derniers billets du blog : </p>
<!--新聞-->
<div class="news"/span>>
<?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>/span>
<?php
}
$recuperation_titre_du_billets_et_contenu->closeCursor()。
?>。
</div>
<!-- FIN NEWS -->
<!-- NEWS2 -->
<div class="news2"/span>>
<?php
$billetsdelapage2 = $bdd->準備("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']))。
如果(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>/span>
<?
}
$billetsdelapage2-> closeCursor();
?>。
</div>
<!-- FIN NEWS2 -->
<!-- NEWS3 -->
<div class="news3"/span>>
<?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']))。
如果(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>/span>
<?
}
$billetsdelapage3-> closeCursor();
?>。
</div>
<!-- FIN NEWS3 -->
</div>/span>
<div class="pagination">
<!--小的錯誤,將在不久后糾正,因為他們的頁數! -->
<a href="index. php">1</a>
<a href="index. php?page=2">2</a>/span>
<a href="index. php?page=3">/span>3</a>
</div>/span>
</body>
</html>/span>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
如果你想從URL中獲得一個引數,如:
HTTP://myurl.com/index.php?myParameter=10
然后使用類似這樣的東西應該可以。
if (isset($_GET['page']){ //check to see if 'page' is set.
$pageNo= $_GET['page']; //然后設定一個等于引數的變數。
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/319560.html
標籤:

