我有下面的代码,显示表 td 中的数据,目前我显示四个表 td,但是当我增加 8 或 12 之类的 no 时,它会变得困惑。我需要每 4 个 td 开始一个新行。我怎样才能实现这个目标?
<tr style="background-color:white;">
<?php
while ($row = mysqli_fetch_array($rs_result)) {
// Display each field of the records.
?>
<td style="vertical-align:middle;padding-top:0px;margin-top:0px;width:32px"><img styel="height:32px;width: 32px;" src="<?php echo $row["gravator"]; ?>"/></td>
<td style="vertical-align:top;margin-left:10px;text-align:left !important;">
<!--<span><img src="<?php echo $row["gravator"]; ?>"/</span>-->
<span style="">#Ad id:<?php echo $row["id"]; ?></span><br>
<span style="margin-left:2px;border-top:1px solid blue;" class="node-text"><?php echo $row["fullname"]; ?> Has Added</span> <br>
<span style="position:absolute;margin-top:-15px;margin-left:2px;width:160px;" class="node-text"><a target="_blank" href="<?php echo $row["url"]; ?>"><?php echo $row["title"]; ?></a></span> <br>
<span style="position:absolute;margin-top:-26px;font-size:smaller;color:silver;margin-left:2px;" class="node-text">On <?php echo $row["datetime"]; ?></span>
</td>
<?php
};
?> </tr>
最佳答案
嗯...这不是最漂亮的方法...但我想它应该适合你。我添加了一个计数器 max_cols
并添加新的 <tr>
每 4 个单元格:
<tr style="background-color:white;">
<?php
$max_cols = 4;
while ($row = mysqli_fetch_array($rs_result)) {
// Display each field of the records.
?>
<td style="vertical-align:middle;padding-top:0px;margin-top:0px;width:32px"><img styel="height:32px;width: 32px;" src="<?php echo $row["gravator"]; ?>"/></td>
<td style="vertical-align:top;margin-left:10px;text-align:left !important;">
<!--<span><img src="<?php echo $row["gravator"]; ?>"/</span>-->
<span style="">#Ad id:<?php echo $row["id"]; ?></span><br>
<span style="margin-left:2px;border-top:1px solid blue;" class="node-text"><?php echo $row["fullname"]; ?> Has Added</span> <br>
<span style="position:absolute;margin-top:-15px;margin-left:2px;width:160px;" class="node-text"><a target="_blank" href="<?php echo $row["url"]; ?>"><?php echo $row["title"]; ?></a></span> <br>
<span style="position:absolute;margin-top:-26px;font-size:smaller;color:silver;margin-left:2px;" class="node-text">On <?php echo $row["datetime"]; ?></span>
</td>
<?php
$max_cols--;
if ($max_cols == 0) {
echo '</tr> <tr style="background-color:white">';
$max_cols = 4;
}
};
?> </tr>
关于PHP 在 mysqli_fetch_array 上中断表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65845922/