dourong9253 2014-05-26 18:20
浏览 7
已采纳

难倒桌子格式

If you remember me from asking the 20+ questions yesterday, I'm still awake and still at it. I'd like to inform anyone who cares I've made GREAT progress.

What I'm trying to figure out now is how to create a minimum about of rows for a table to have. The reason being is if the Table on my page doesn't have exactly 12 rows, it looks bad. The problem is there won't always be 12 rows worth of data in the SQL Database, so I need to find a way to make it so if there's not 12 results it fills in the table with a character of choice, probably "--"

Also, I'm trying to figure out how to create pages for the table. I haven't done any research on that one yet and it's not what this questions about, but if you know how and want to drop it here, that'd be cool.

  • 写回答

3条回答 默认 最新

  • dpj775835868 2014-05-26 18:38
    关注

    There are a few different ways you could go about this, but the basic idea is to know how many rows you printed, and if it's less than 12, print empty rows until you have the 12 you need. Here's one example:

    Assuming you have your query results in an array called $data:

    <table>
    <?php
        foreach ($data as $row) {
            echo "<tr><td>{$row['col1']}</td><td>{$row['col2']}</td><td>{$row['col3']}</td></tr>";
        }
        if (count($data) < 12) {
            for ($i=0; $i < 12-count($data); $i++) {                        
                echo "<tr><td colspan='3'>EMPTY ROW</td></tr>";
            }
        }
    ?>
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)