PHP 在 mysqli_fetch_array 上中断表行

标签 php line-breaks

我有下面的代码,显示表 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/

相关文章:

css - 控制换行符使线条宽度相等

php - 在 php 中运行 windows 命令

php - MYSQL查询优化

html - 如何在不使用 <br/> 的情况下从 css 换行?

html - 标题元素中的换行符

导出到文本文件时带有换行符的git日志

vim - Vim自动换行

java - 使用此代码 (PHP) 向多个设备发送推送通知

javascript - 如何保存选择选项的名称而不是值

php - 删除成员(member)数据库中注册的成员(member)