在PHP中创建产品的网格视图

时间:2013-03-17 03:09:51

标签: php html mysql css

非常适合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

            }

我如何创建网格视图,例如使用列来显示我的数据?我认为这将是某种循环被添加并可能使用表来显示我的数据?

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

你可以通过创建div和浮点数得到这个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的最大高度和宽度