简体   繁体   English

我如何回显表 <tr> 水平而不是垂直的while循环?

[英]How do I echo out table <tr> horizontally instead of vertically with while-loop?

My code echoing the table vertically and thats not what I want. 我的代码在垂直方向上回显了表格,这不是我想要的。 I have been trying to get it to work the way I want it to but I find it very hard to find a solution becasue of the while loop forcing the table to be vertically. 我一直在尝试使其按我想要的方式工作,但是由于while循环迫使表垂直,我发现很难找到解决方案。

<table style="width:100%">
<?php 
            while($row = mysqli_fetch_array($result)){

              echo "<tr><td>$row['user'] </td></tr>";
             }
?>
</table> 

As the comment says, a <tr> is a Table Row, which means it will create a new row vertically when displayed. 如注释所述, <tr>是表行,这意味着它在显示时将垂直创建一个新行。 The code below puts everything in one row, which will display it horizontally. 下面的代码将所有内容都放在一行中,然后将其水平显示。

<table style="width:100%">
<tr>
<?php 
            while($row = mysqli_fetch_array($result)){

              echo "<td>$row['user'] </td>";
             }
?>
</tr>
</table> 

As Subin Thomas stated in the comment, tr is used for rows, so basically, they will be vertical. 如Subin Thomas在评论中所述, tr用于行,因此基本上,它们将是垂直的。 The td s inside the row will be horizontal. 该行内的td将为水平。 So, to achieve what you want, you may use this code: 因此,要实现所需的功能,可以使用以下代码:

<table width="100%">
    <tr>
        <?php 
            while($row = mysqli_fetch_array($result)){
                echo "<td>$row['user'] </td>";
            }
        ?>
    </tr>
</table>

What we did, is move the tr out of the loop, and loop only the td s. 我们所做的是将tr移出循环,并仅循环td

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM