dongxun4110 2019-07-09 05:42 采纳率: 0%
浏览 112
已采纳

PHP和Bootstrap中的多项旋转木马

I have an e-commerce site and am trying to add related products in a carousel at the bottom of the product page:

I query my DB to get the related products and then create a simple Bootstrap carousel.

However, I want there to be more than one item on each slide, but the number of items might change depending on screen size.

Each carousel item is a fixed width and height:

.carousel-item{
    width:300px;
    height:400px;
    border:1px solid var(--grey3);
}

I tried splitting my carousel item into columns with Bootstrap (as shown here https://www.youtube.com/watch?v=SAyLQVR1t5s) but I need them to be a specific size to accommodate product info so having flexible columns within a carousel item to hold each product won't work when I resize the screen.

My PHP code is as follows:

$related .= '<div id="carouselExampleControls" class="carousel slide" data-ride="carousel">';
$related .= '<div class="carousel-inner">';

$i = 0;
$params = [$product_name,$product_name,$_SESSION['locale']['product_set']];
$sql = "SELECT * FROM products WHERE MATCH(product_name) AGAINST(?) AND product_name!=? AND product_set=? LIMIT 15";
$stmt = DB::run($sql,$params);
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
    $related_product_id = $row["id"];
    $related_product_name = $row["product_name"];

    $related .= '<div class="carousel-item';
    if($i==0){$related .= ' active';}
    $related .= '">';
    $related .= '//product_info';
    $related .= '</div>';

    $i++;
}

$related .= '</div>';
$related .= '<a class="carousel-control-prev" href="#carouselExampleControls" role="button" data-slide="prev">';
$related .= '&lsaquo;';
$related .= '</a>';
$related .= '<a class="carousel-control-next" href="#carouselExampleControls" role="button" data-slide="next">';
$related .= '&rsaquo;';
$related .= '</a>';
$related .= '</div>';

展开全部

  • 写回答

1条回答 默认 最新

  • duan198811 2019-07-31 00:57
    关注

    For future reference, I stopped using Bootstrap and used https://kenwheeler.github.io/slick/ as suggested and it is so much easier

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部