我正在使用PHP和MySQL的網站上工作,並有一些問題,從數據庫行生成網頁網址。動態Html頁面從PHP與PHP
我只有3頁connection.php(MySQL連接)的index.php(其中與產品的詳細信息URL按鈕顯示人的產品/內容縮略圖)和details.php我想要顯示的單品信息。
從的index.php我添加一個鏈接重定向與這details.php頁:
<a href="details.php?id=<?php echo $row['ID']; ?>"
它的工作,但最大的問題是在details.php因爲劇本不顯示單產品細節,但顯示所有產品,請有人可以幫助我?謝謝
的index.php代碼
......other html code......
<div class="row">
<?php
require_once 'connection.php';
$query = "SELECT * FROM campi_name";
$stmt = $DBcon->prepare($query);
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
?>
<div class="col-sm-4 col-md-3">
<div class="thumbnail">
<img src="<?php echo $row['Thumbnail']; ?>" alt="<?php echo $row['Title']; ? >">
<div class="caption">
<h4><?php echo substr($row['Title'], 0, 30); ?></h4>
<p><?php echo $row['Brand']; ?></p>
<?php echo $row['ID']; ?>
<p><a href="#" class="btn btn-primary btn-lg" role="button">Cofronta</a> <a href="dettagli.php?id=<?php echo $row['ID']; ?>" class="btn btn-default btn-lg" role="button">Dettagli</a></p>
</div>
</div>
</div>
<?php
}
?>
......other html code......
connection.php代碼
$DBhost = "localhost";
$DBuser = "root";
$DBpass = "";
$DBname = "prodotti";
try {
$DBcon = new PDO("mysql:host=$DBhost;dbname=$DBname",$DBuser,$DBpass);
$DBcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $ex){
die($ex->getMessage());
}
?>
details.php代碼
......other html code......
<div class="container">
<div class="row">
<?php
require_once 'connection.php';
$query = "SELECT * FROM campi_name";
$stmt = $DBcon->prepare($query);
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
?>
<div class="col-sm-4 stylerow">
<a href="<?php echo $row['AffiliateLink']; ?>" class="thumbnail">
<img src="<?php echo $row['Thumbnail']; ?>" alt="<?php echo $row['Title']; ? >">
</a>
</div>
<div class="col-sm-8 stylerow">
<h2><?php echo $row['Title']; ?></h2>
<p><?php echo $row['Brand']; ?></p>
<button type="button" class="btn btn-primary btn-lg">Amazon</button>
</div>
</div>
</div><!-- /.container -->
......other html code......
看'SELECT * FROM campi_name',你需要告訴它你想要什麼。 'SELECT * FROM campi_name where id =?'然後綁定GET'ID'。 '$ stmt-> execute(array($ _ GET ['id']));' – chris85
你將需要使用details.php上的GET,就像chris85說的 –