簡體   English   中英

從數據庫將檢索到的值傳遞到另一個頁面

[英]Passing retrieved value from database into another page

單擊鏈接后,如何從該頁面到另一個頁面檢索特定的產品詳細信息?

這是我的代碼,用於顯示數據庫中的所有產品:

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

您可以將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']; http://php.net/manual/zh/function.filter-input.php上檢查filter_input的文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM