代码之家  ›  专栏  ›  技术社区  ›  weng tee

在主ID中引用其他产品ID

  •  1
  • weng tee  · 技术社区  · 7 年前

    item.php 我想参考两个额外的追加销售id的同一页上,以及与主 product_id

    这就是我当前页面的外观。 enter image description here

    我在products表中添加了两个新列,即 product_upsell_one product_upsell_two 本质上持有现有产品的id。

    我的产品表:

    products table

    我的图像表: enter image description here

    我用这个函数来调用每个upsell图像

    function get_upsell_image_for_product_upsell_one() {
    
    
    
    $query = query("SELECT product_image, product_title, product_price FROM products WHERE product_id IN (SELECT product_upsell_one FROM products WHERE product_id =   " . escape_string($_GET['id']) . " )");      
    confirm($query); //runs the confirm method above 
    
    
    while ($row = fetch_array($query)) {
    
    $product_image = display_image($row['product_image']); // runs display image function    
    
    
    $upsell = <<<DELIMETER
    
    
    
    
                <ul class="product-list">
    
                    <li>
    
                        <div class="product">
    
                            <a href="#" class="product-image">
    
    
                                <img src="../resources/{$product_image}" alt="Product">
    
                            </a>
    
    
    
    
                            <div id="container">
    
                                <div id="box">
    
                                    <a href="#" class="btn-view">{$row['product_title']}</a>
    
                                </div>
    
    
                            </div>
    
    
                        </div>
    
                    </li>
    
                </ul>
    
    
    
    
    
    
    
    
    DELIMETER;
    
    echo $upsell;
    
    
    } //closes while loop
    
    
    
    } // end of function 
    

    虽然我的代码在dev模式下运行得很好,但我想知道我是否在为生产环境中的问题做准备,最好是通过引用 产品追加销售 在另一张桌子上。如何最好地引用其他ID。

    1 回复  |  直到 7 年前
        1
  •  1
  •   PHP_Developer    7 年前

    我会有一个产品upsell表,外键指向父产品和upsell项。这样你就可以有很多或很少的追加销售项目,你想要的。

    推荐文章