对 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
}
我将如何着手创建 GridView ,例如使用列来显示我的数据?我想这会是要添加的某种循环,并可能使用表格来显示我的数据?
非常感谢任何帮助。
最佳答案
您可以通过创建 div 并将该 div float 到左侧来点此,这将创建 GridView
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的最大高度和宽度
关于php - 在 PHP 中创建产品的 GridView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15457089/