[英]Passing retrieved value from database into another page
how can i retrieve specific product details from this page to another page when i click the link? 单击链接后,如何从该页面到另一个页面检索特定的产品详细信息?
This is my code for displaying all products in database: 这是我的代码,用于显示数据库中的所有产品:
<div class="features_items"><!--features_items-->
<h2 class="title text-center">Features Items</h2>
<?php
$product_array = $db_handle->runQuery("SELECT * FROM tblforface ORDER BY prodid ASC");
if (!empty($product_array)) {
foreach($product_array as $key=>$value){
?>
<div class="col-sm-4">
<div class="product-image-wrapper">
<div class="single-products">
<div class="productinfo text-center">
<img src="images/shop/product12.jpg" alt="" />
<h2><?php echo "₱".$product_array[$key]["prodprice"]; ?></h2>
<p><?php echo $product_array[$key]["prodname"]; ?></p>
<a href="../homescreen/product/product.php" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
</div>
<div class="product-overlay">
<div class="overlay-content">
<h2><?php echo "₱".$product_array[$key]["prodprice"]; ?></h2>
<p><?php echo $product_array[$key]["prodname"]; ?></p>
<a href="../homescreen/product/product.php" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
</div>
</div>
</div>
<div class="choose">
<ul class="nav nav-pills nav-justified">
<li><a href=""><i class="fa fa-plus-square"></i>Add to wishlist</a></li>
<li><a href=""><i class="fa fa-plus-square"></i>Add to compare</a></li>
</ul>
</div>
</div>
</div>
You can add the id into a query string, like http://blah.com/product.php?id=123
您可以将ID添加到查询字符串中,例如http://blah.com/product.php?id=123
<a href="../homescreen/product/product.php?id=<?= $product_array[$key]["id"]; ?>" class="btn btn-default add-to-cart">
<i class="fa fa-shopping-cart"></i>Add to cart
</a>
And in your other page, 在您的其他页面中
$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
We do that instead of the dangerous $id = $_GET['id'];
我们这样做是代替危险的$id = $_GET['id'];
. 。 Check the docs for filter_input here http://php.net/manual/en/function.filter-input.php 在http://php.net/manual/zh/function.filter-input.php上检查filter_input的文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.