将检索到的值从数据库传递到另一个页面

时间:2017-09-20 09:27:55

标签: php

当我点击链接时,如何从此页面检索特定产品详细信息到另一页?

这是我在数据库中显示所有产品的代码:

<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>

1 个答案:

答案 0 :(得分:0)

您可以将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>

在您的其他页面中,

$id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);

我们这样做而不是危险的$id = $_GET['id'];。在此处查看文档filter_input http://php.net/manual/en/function.filter-input.php