doutu3352 2018-07-14 09:39
浏览 89
已采纳

每行显示3个产品

I'm having issues displaying products on a site correctly, i'm trying to show 3 products on each row which will keep the same size and not break the display up.

Code:

<?php

    //error_reporting(1);

    // Query depending ...
    $theQuery = "";
    if (!isset($_GET['catId'])) {
        $theQuery = "SELECT * FROM `products` WHERE `product_active`='Y' ORDER BY RAND() LIMIT 24";
    } else {
        $theQuery = "SELECT * FROM `products` WHERE `product_category_id`='{$_GET['catId']}' AND `product_active`='Y' ORDER BY RAND() LIMIT 24";
    }

    // Execute 1 of the 2 queries.
    $randomProducts = DB::getInstance()->select($theQuery);

?>

<div class="container-fluid" id="container">
<div class="col-md-8">
<div class="row equal">

<?php foreach ($randomProducts as $product) { ?>

            <?php $p = json_decode($product['product_json_body'], true); ?>

                <?php if (!empty($p['name'])) { ?>

                         <div class="item col-xs-4 col-lg-4">
                          <div class="thumbnail">   
                            <div class="space-ten"></div>                         
                            <img src="<?php echo $p['images'][0]; ?>" alt="" style="width:450px; height:450px;" class="group list-group-image">                         
                            <div class="caption">
                              <h4 class="pull-right"><span class="text-danger"><b>$<?php echo number_format($p['priceRange']['maxPrice'], 2); ?></b></span></h4>
                              <h4><span class="text-success"><b><a href="product.php?productId=<?php echo $product['product_id']; ?>"><?php echo $p['name']; ?></a></b></span></h4>
                              <p><?php echo $p['descriptionText']; ?></p>
                            </div>                          
                            <div class="space-ten"></div>                       
                            <div class="btn-ground text-center">
                            <form action="cart.php" method="post" class="form-horizontal container-fluid">
                                <input type="hidden" name="cartQTy" value="1" />
                                <input type="hidden" name="cartPId" value="<?php echo $product['product_id']; ?>" />
                                <input type="hidden" name="cartPNm" value="<?php echo $p['name']; ?>" />
                                <input type="hidden" name="cartPce" value="<?php echo number_format($p['priceRange']['maxPrice'], 2); ?>" />
                                <input type="hidden" name="cartUId" value="<?php echo $member; ?>" />
                                <input type="hidden" name="cartImg" value="<?php echo $p['images'][0]; ?>" />
                                <input type="hidden" name="cartTfs" value="<?php echo "source01"; ?>" />                                
                                <button type="submit" class="btn btn-primary"><i class="fa fa-shopping-cart"></i> <span class="glyphicon glyphicon-shopping-cart"></span> Add To Cart</button>
                                <!--<button type="button" class="btn btn-primary" data-toggle="modal" data-id="<?php echo $product['product_id']; ?>" data-target="#product_view"><i class="fa fa-search"></i> <span class="glyphicon glyphicon-eye-open"></span> Quick View</button>-->
                            </form> 
                            </div>                      
                            <div class="space-ten"></div>                         
                          </div>

                <?php } ?>              

    <?php } ?>  

</div></div></div>

It's quite basic code, i'm using the bootstrap framework, with just some PHP to loop out the products, a test display is here: https://www.we-love-unicorns.club/ everytime i try to fix it, i make it worse, i have removed and added divs nothing seems to work, can anyone see any issues i may have missed?

  • 写回答

1条回答 默认 最新

  • drrrdo0802 2018-07-14 09:44
    关注

    You'll be relieved to know this is a simple fix. You are just missing a closing </div> tag inside your foreach loop. Like so

                         <div class="item col-xs-4 col-lg-4">
                          <div class="thumbnail">   
                            <div class="space-ten"></div>                         
                            <img src="<?php echo $p['images'][0]; ?>" alt="" style="width:450px; height:450px;" class="group list-group-image">                         
                            <div class="caption">
                              <h4 class="pull-right"><span class="text-danger"><b>$<?php echo number_format($p['priceRange']['maxPrice'], 2); ?></b></span></h4>
                              <h4><span class="text-success"><b><a href="product.php?productId=<?php echo $product['product_id']; ?>"><?php echo $p['name']; ?></a></b></span></h4>
                              <p><?php echo $p['descriptionText']; ?></p>
                            </div>                          
                            <div class="space-ten"></div>                       
                            <div class="btn-ground text-center">
                            <form action="cart.php" method="post" class="form-horizontal container-fluid">
                                <input type="hidden" name="cartQTy" value="1" />
                                <input type="hidden" name="cartPId" value="<?php echo $product['product_id']; ?>" />
                                <input type="hidden" name="cartPNm" value="<?php echo $p['name']; ?>" />
                                <input type="hidden" name="cartPce" value="<?php echo number_format($p['priceRange']['maxPrice'], 2); ?>" />
                                <input type="hidden" name="cartUId" value="<?php echo $member; ?>" />
                                <input type="hidden" name="cartImg" value="<?php echo $p['images'][0]; ?>" />
                                <input type="hidden" name="cartTfs" value="<?php echo "source01"; ?>" />                                
                                <button type="submit" class="btn btn-primary"><i class="fa fa-shopping-cart"></i> <span class="glyphicon glyphicon-shopping-cart"></span> Add To Cart</button>
                                <!--<button type="button" class="btn btn-primary" data-toggle="modal" data-id="<?php echo $product['product_id']; ?>" data-target="#product_view"><i class="fa fa-search"></i> <span class="glyphicon glyphicon-eye-open"></span> Quick View</button>-->
                            </form> 
                            </div>                      
                            <div class="space-ten"></div>                         
                          </div>
                        </div> <!-- This div tag! -->
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题