我正在制作一个电子商务网站。我的页面上充满了待售商品的图片和图片下商品的详细信息。我在图片下面还有一个按钮,这样当点击时,用户可以查看有关该项目的更多信息。但我不知道该怎么做。下面是我的代码,显示数据库中的信息和图像。
<?php
// Default query for this page:
$q = "SELECT * FROM item";
// Create the table head:
echo '
';
// Display all the items, linked to URLs:
$r = mysqli_query ($dbc, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
$directory = '/uploads';
$file= $row['image_name'];
// Display each record:
echo "
<div class='col-lg-3'>
<image src=$directory/$file title='$row[image_name]' width='213' height='200'></br></br>
<p align='left'> Brand : {$row['brand']}</br> Type: {$row['category']} </br> Price : £{$row['price']} </p>
<a class='btn btn-primary' href='showitem.php' role='button'>More Details »</a>
</br></br></br>
</div>
";
}
echo '</tbody>';
echo '</table>';
mysqli_close($dbc);
?>
将标识符添加到按钮的链接中,如下所示:
<a class='btn btn-primary' href='showitem.php?item={$row['id']}' role='button'>More Details »</a>
然后,您可以使用showitem.php生成详细的产品描述,使用$_GET['item']
首先,您需要表中的唯一id,然后在类似showitems.php?pid=1
的url中传递您的产品id,并使用从url获取的条件pid进行查询。
SELECT * FROM item WHERE id = "$_GET['pid']"