dongmei6426 2019-01-08 06:24
浏览 81
已采纳

使用for循环的html表与第一列静态?

i want to populate table that has first field static and other fields are coming from database using for loop

blank column are coming from database using for loop and i have to insert first column statically how do i do that?

  for($i=0;$i<5;$i++){
     <td></td>
     <td></td>
     <td></td>
     <td></td>
   }

i want these kind of result

  story  blank blank blank
  games  blank blank blank
  number blank blank blank
  • 写回答

1条回答 默认 最新

  • dragon202076 2019-01-08 06:35
    关注

    I recommend you to read more about how to create a table and its rows (https://www.w3schools.com/html/html_tables.asp).

    <?php for($i = 0; $i < 5; $i++):?>
        <tr>
            <td>my static value</td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    <?php endfor;?>
    

    Also, please keep those static values to an array and add them using the same for.

    <?php 
    $myArrayWithMyStaticValues = ['item1', 'item2', 'item3', 'item4', 'item5'];
    for($i = 0; $i < 5; $i++):?>
        <tr>
            <td><?=$myArrayWithMyStaticValues[$i];?></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
    <?php endfor;?>
    

    But be careful because you need to have the same number of items in your array as the for condition.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline