在 2 列中显示单个 PHP 数据

Display Single PHP Data in 2 Columns

我想将单个数据显示为 2 列,作为 mysql table 结果在我的 PHP 文件中。我已经尝试使用我的代码,但结果显示了相同的数据,如 <tr><td>result1</td><td>result1</td>

我已经尝试使用我的代码,但结果如下:

| result 1 | result 1 |
| result 2 | result 2 |
| result 3 | result 3 |
| result 4 | result 4 |
| result 5 | result 5 |
| result 6 | result 6 |
| result ... | result ... |

但我需要结果

| result 1 | result 2 |
| result 3 | result 4 |
| result 5 | result 6 |
| result 7 | result 8 |
| result ... | result ... |

这是我的代码:

    <?php
        include('config.php');
        $data_content = '';
        $qry = "SELECT DISTINCT bankName FROM bankData ORDER BY bankName";
        $result = mysql_query($qry);
        while($row = mysql_fetch_array($result))
            {
                 $data_content.= "<a href='bank/".$row['bank_Name'].".php'> ".$row['bankName']."</a>";
            }
        mysql_close();
        ?>
<!DOCTYPE html>
<html lang="en">
<head>
<body>
<div>   
<table border="1">
    <?php
         for($i=0; $i<=1; $i++)
            {
            echo "<tr>";
            for($j=0; $j<=1; $j++)
            {
             echo "<td>";
             echo $data_content;
             echo "</td>"; 
            }
             echo "</tr>";
            }
    ?>
</table>
</div>
</body>
</html>

请帮帮我。

把循环放在下面:

<table border="1">
<?php
$i = 0;
while($row = mysql_fetch_array($result))
    {
         // Odd row opens
         if (++$i % 2 != 0) echo "<tr>";
         echo "<td><a href='bank/".$row['bankName'].".php'> ".$row['bankName']."</a></td>";
         // Even row closes
         if ($i % 2 == 0) echo "</tr>";  
    }
    // If you have an odd number of results, add a blank column and close the last row
    if ($i % 2 != 0)  echo "<td></td></tr>";
?>
</table>

(++$i % 2 != 0) 递增 $i 并检查它是否为奇数。如果是奇数,它将用 </tr> 打开 table 行,下一次迭代将用 </tr>.

关闭 table 行