PHP中的HTML表格网格

PHP中的HTML表格网格,php,html,html-table,Php,Html,Html Table,我目前正在做一些基本的PHP,我正在从mysql获取产品,并在一个表中显示每个产品的相应细节 目前,它们是一个在另一个之下 Product1 Name Product1 Price Product1 Description Product2 Name Product2 Price Product2 Description 现在我想把它们显示在3列的网格中。 这意味着并列显示3个产品,然后第4个产品显示在第1个产品下面,依此类推 $displayAllProducts.= "

我目前正在做一些基本的PHP,我正在从mysql获取产品,并在一个表中显示每个产品的相应细节

目前,它们是一个在另一个之下

Product1 Name
Product1 Price
Product1 Description

Product2 Name
Product2 Price
Product2 Description
现在我想把它们显示在3列的网格中。 这意味着并列显示3个产品,然后第4个产品显示在第1个产品下面,依此类推

$displayAllProducts.=
        "
            <tr><td>Product Name : </td><td>$productName</td></tr>
            <tr><td>Product Price : </td><td>$productPrice</td></tr>
            <tr><td>Product Qty  : </td><td>$productQty</td></tr>
            <tr><td colspan =\"2\"><img src=\"$imagePath\" width = \"100\" height = \"100\"></td><td></td></tr>
            <tr><td colspan =\"2\"><a href=\"singleProduct.php?pid=$productID&uid=$uid\">View Product<br/><br/><br/></td><td></td></tr>   
         ";



<table>
 <?php
  echo $displayAllProducts;
 ?>
</table>
$displayAllProducts=
"
产品名称:$productName
产品价格:$productPrice
产品数量:$productQty
查看产品


";
在没有看到实际代码在
db
行中循环的情况下,这里有一个总体思路。这将使每个
$displayAllProducts
都有自己的表,嵌套在主表

$i=1;  // start a general counter
while($i<$number_of_db_rows){
if($i%3 = 1) {   // If number is 1,4,7,etc start a new row
$displayAllProducts.= "<tr>"; 
}
$displayAllProducts.=
    "
        <td>     // put each db row inside a cell
        <table>  // create a bounding table
        <tr><td>Product Name : </td><td>$productName</td></tr>
        <tr><td>Product Price : </td><td>$productPrice</td></tr>
        <tr><td>Product Qty  : </td><td>$productQty</td></tr>
        <tr><td colspan =\"2\"><img src=\"$imagePath\" width = \"100\" height = \"100\"></td><td></td></tr>
        <tr><td colspan =\"2\"><a href=\"singleProduct.php?pid=$productID&uid=$uid\">View Product<br/><br/><br/></td><td></td></tr>
        </table> 
        </td>  
     ";
if($i%3 = 0) {   // If number is 3,6,9,etc close the row
$displayAllProducts.= "</tr>";
}
$i++ // increase the counter to start again
}  // ends the loop


<table>
<?php
echo $displayAllProducts;
?>
</table>
$i=1;//启动一个通用计数器

然而,你的文章并没有以问号结尾。你的问题到底是什么?你已经试图达到这个目的了吗?你在哪里被卡住了?另外,刚刚注意到你原来的表代码在每行的
单元格中不一致。前3个有2个
,但最后2个有
colspan=\'2\'
现在有3个