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>£$row[2]</strong><br>"; //this shows the product price
}
我将如何创建网格视图,例如使用列显示数据?我想这将是某种添加的循环,也许使用表来显示我的数据?
任何帮助是极大的赞赏。
最佳答案
您可以通过创建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>£$row[2]</strong><br>"; //this shows the product price
echo "</div>";
}
和CSS
.container{
float:left;
}
您可以
还要设置div的最大高度和宽度