doupao5296 2018-05-10 20:18
浏览 72
已采纳

如何在PHP生成的表的顶部显示空行

I have a PHP code that generates a table with mysql query on the page. I would like to display 3 empty rows below the header row at the top of the table. How can I achieve this? is it possible? thanks for your help and time!

<html>
<head>
</head>
<body>

 <table class="tbrp">
 <tr>
  <th>Rp1</th> 
  <th>Rp2</th>
  <th>Rp3</th>
  <th>Rp4</th>
  <th>Rp5</th>
  <th>Rp6</th>
  <th>Rp7</th>
  <th>Rp8</th>
 </tr>


 <?php

  include ("config.php");

  $sql = "SELECT Rp1, Rp2, Rp3, Rp4, Rp5, Rp6, Rp7, Rp8 FROM Rptable";
  $result = $conn->query($sql);
  if ($result->num_rows > 0) {

   // output data of each row
   while($row = $result->fetch_assoc()) 
   {
        echo "<tr><td>" . $row["Rp1"] . "</td><td>" . $row["Rp2"]. "</td><td>". $row["Rp3"]. "</td><td>". $row["Rp4"].  "</td><td>".$row["Rp5"]. "</td><td>". $row["Rp6"]. "</td><td>". $row["Rp7"] . "</td><td>".$row["Rp8"] .  "</td></tr>";

   }

      echo "</table>";

} else { echo "0 results"; }
$conn->close();

    ?>   

</table>



    </body>
</html>
  • 写回答

6条回答 默认 最新

  • dongshou2017 2018-05-10 20:23
    关注

    You can do it with plain HTML or you can do it with PHP loops (better way if you want to change 3 rows for example to 30, it gives you the flexibility). And please, try to indent your code so that it's easy readable and maintainable. Here is the code:

    <html>
        <head>
        </head>
        <body>
            <table class="tbrp">
                <tr>
                    <th>Rp1</th> 
                    <th>Rp2</th>
                    <th>Rp3</th>
                    <th>Rp4</th>
                    <th>Rp5</th>
                    <th>Rp6</th>
                    <th>Rp7</th>
                    <th>Rp8</th>
                </tr>
                 <?php
                    include ("config.php");
    
                    for ($i = 0; $i < 3; $i++) {
                        echo "<tr>";
    
                        for ($j = 0; $j < 8; $j++) {
                            echo "<td></td>";
                        }
    
                        echo "</tr>";
                    }
    
                    $sql = "SELECT Rp1, Rp2, Rp3, Rp4, Rp5, Rp6, Rp7, Rp8 FROM Rptable";
                    $result = $conn->query($sql);
                    if ($result->num_rows > 0) {
                        // output data of each row
                        while ($row = $result->fetch_assoc()) {
                            echo "<tr><td>" . $row["Rp1"] . "</td><td>" . $row["Rp2"]. "</td><td>". $row["Rp3"]. "</td><td>". $row["Rp4"].  "</td><td>".$row["Rp5"]. "</td><td>". $row["Rp6"]. "</td><td>". $row["Rp7"] . "</td><td>".$row["Rp8"] .  "</td></tr>";
                        }
    
                        echo "</table>";
                    } else {
                        echo "0 results";
                    }
    
                    $conn->close();
                ?>
            </table>
        </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题