2013-03-17 44 views
0

对PHP很新颖,请耐心等待。在PHP中创建产品的网格视图

正如您从我的代码片段中看到的,我只是将产品信息显示在彼此之下,然后使用while重复循环。这显然显示了我的相关数据在一个列中,一个在另一个之下。

while ($row = mysqli_fetch_row($result)){ 

    echo "<img src=\"images/album1.jpg\"/><br>"; //this will eventually show the product image 
    echo "<a href=\"product.php?id=$row[0]\">$row[1] </a><br>"; //this shows the product name 
    echo "<strong>&pound$row[2]</strong><br>"; //this shows the product price 

      } 

我将如何去建立一个网格视图,例如使用列,以显示我的数据?我认为这将是某种循环被添加,也许使用表来显示我的数据?

任何帮助,非常感谢。

回答

0

你可以通过创建格点这个和浮空DIV向左这将创建网格视图

while ($row = mysqli_fetch_row($result)){ 
    echo "<div class='container'>"; 
    echo "<img src=\"images/album1.jpg\"/><br>"; //this will eventually show the product image 
    echo "<a href=\"product.php?id=$row[0]\">$row[1] </a><br>"; //this shows the product name 
    echo "<strong>&pound$row[2]</strong><br>"; //this shows the product price 
    echo "</div>"; 
    } 

和CSS

.container{ 
    float:left; 
} 

可以 还设置了最大高度和DIV的宽度

+1

工作完美。谢谢,我的朋友。 – user2178458 2013-03-17 03:15:51