duanju6788 2015-06-17 14:27
浏览 19
已采纳

在修复html表上显示php数组而不影响行数

I am still in the process of learning PHP and would like to seek for your assistance regarding my concern. I already know how to display an array into an html table which i usually do with my forms. Then suddenly i came into this issue wherein there should be a fix table with a fix number of rows (lets say about 5 rows).

Now if i would display information coming from a specific user and that user only has 2 rows of data from mysql then i will only have 2 rows displayed on my html table.

What happens:

*****************
** A ** B ** C **
*****************
** 1 ** 2 ** 3 **
*****************
** 4 ** 5 ** 6 **
*****************

What i want as an output:

*****************
** A ** B ** C **
*****************
** 1 ** 2 ** 3 **
*****************
** 4 ** 5 ** 6 **
*****************
**   **   **   **
*****************
**   **   **   **
*****************

Is there a neat way to code this. Your idea is already a big help; I am not asking for codes but you can somehow guide me on what i can do here in order to achieve the output i want.

Thanks.

  • 写回答

3条回答 默认 最新

  • douyan8070 2015-06-17 14:32
    关注

    You could maintain a second counter with your fixed number calculations. In pseudo-code, it might look like this:

    $rowCount = 0;
    while (getNextDataRow()) {
        printDataRow();
        $rowCount++;
    }
    while ($rowCount <= 5) {
        printEmptyRow();
        $rowCount++;
    }
    

    Note that this would add empty rows when needed, but it wouldn't constrain the number of rows if the data contains more than 5. It's up to you what to do in that case. The data query could have a LIMIT to prevent that from happening, the first while loop could have a check for $rowCount == 5 and exit the loop, etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?
  • ¥15 讲解电路图,付费求解
  • ¥15 有偿请教计算电磁学的问题涉及到空间中时域UTD和FDTD算法结合的
  • ¥15 three.js添加后处理以后模型锯齿化严重
  • ¥15 vite打包后,页面出现h.createElement is not a function,但本地运行正常