2015-08-23 163 views
-2

搜索结果应该显示像这样enter image description hereDIV中while循环在PHP

但我的结果堆叠在每个之上。 enter image description here

这里是我的代码:

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

那些块是一个容器内。 我添加了一个引导类,为了更好的设计。

+2

看起来是一个CSS问题。也包括样式表。 – Ahmad

+0

尝试在您的卡片样式中使用浮动并在容器样式中使用适当的宽度 – JSB

+0

尚未添加任何CSS @Ahmad – Sadman

回答

0

没有CSS问题,人们只知道如何往下投票时,他们不知道答案,唉!

我在while while循环中使用了一个计数器。

这将检查的时候,已经有4块/产品中的单排那么它会创建一个新的行

<?php 

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

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

?> 
1

您可以使用thumbnails with custom content

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

非常感谢您的提示,现在要查找,希望它能对您有所帮助。 – Sadman

+0

我确实使用了你告诉我的方式,但是现在它显示的是这样的: http://imgur.com/RtoGcBX 我想要的只是显示结果,比如我发布在顶部的第一张图片。我用了左边的浮动,但没有工作。 – Sadman