php - 在 PHP 中创建产品的 GridView

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

            }

我将如何着手创建 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>&pound$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/

相关文章:

php - 如何在 php 中发布整个 json 对象?

php - 如何在印度标准时间中插入日期时间并在检索格式日期时间后仅在 php 中插入日期时间?

php - 有没有比事务更高效的方法?

Javascript/HTML 5 视频 - 检测视频是否未加载

php - WordPress 提取数据库信息并将其显示到页面中

MYSQL Concat、Left Join、Group解决方案

php - 没有获得正确数量的赞成票和反对票

html - 在没有内容的 Div 上添加链接

html - 在按钮上禁用图像

mysql 触发代码从 TOAD 部署,但不是从 phpmyadmin 或 mysql 控制台部署