Bootstrap php中while循环内的div

t8e9dugd  于 2022-12-07  发布在  Bootstrap
关注(0)|答案(2)|浏览(178)

搜索结果应如下所示

但我的结果是叠加在每个上面。

下面是我的代码:

<div class="container">

<?php
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("thesis") or die(mysql_error());

    $search = trim( $_POST['SearchKeywords']);

    $query = " SELECT * FROM new_data WHERE Product_Title or Product_link LIKE'%$search%' "; 

    $sql = mysql_query($query) or die(mysql_error());
    $count = mysql_num_rows($sql);

    $count == 0;

    if ($count == 0) {

        echo "Sorry, Nothing Found !!";

    }else{

    while ($row = mysql_fetch_array($sql)) 
    {
        $img = $row ['Product_Img'];
        $link = $row ['Product_link'];
        $title = $row ['Product_Title'];
        $price = $row ['Product_Price'];
?>

<div class="card"> 
  <div class="front alert alert-success"> 
    <?php echo "$title"; 
         echo "<img src='$img' width='80px' height='100px'>"; 
         echo "$price"; ?> 
  </div> 
</div>
<?php
     };
    };
?>
</div>  <!-- Container -->

这些div块在一个容器中。我添加了一个引导类,以便更好地设计。

8yoxcaq7

8yoxcaq71#

您可以将缩略图与自定义内容一起使用

<div class="row">
  <div class="col-sm-6 col-md-4">
    <div class="thumbnail">
      <img src="..." alt="...">
      <div class="caption">
        <h3>Thumbnail label</h3>
        <p>...</p>
        <p><a href="#" class="btn btn-primary" role="button">Button</a> <a href="#" class="btn btn-default" role="button">Button</a></p>
      </div>
    </div>
  </div>
</div>
oyxsuwqo

oyxsuwqo2#

我在while循环中使用了一个计数器。
它将检查,如果单行中已经有4个块/产品,则它将创建一个新行

<?php

    if($productCount == 0)
    {
        echo "<div class='row'>";               }
    }
        $productCount++;

    if($productCount==4)
    {
        echo "</div>" ;
        $productCount = 0;
    }
    
?>

相关问题