dpi74187 2013-07-08 08:23
浏览 15
已采纳

动态表的唯一ID

I will be generating a HTML table with data pulled from MySQL.The number of rows in my MySQL table are not fixed.

<?php
  while($row=mysql_fetch_assoc($result))
  { ?>
    <tr>
      <td><?php echo $row['col1'];?></td>
      <td><?php echo $row['col2'];?></td>
    </tr>
  <?php } ?>

Now how do I have the table rows and table data elements assigned unique id ??

Another loop to generate them won't work as I can't set an exit condition for the new loop as number of rows are not fixed.

Please guide me as to how to go forward about it. I can only use Javascript and not JQUERY.

  • 写回答

2条回答 默认 最新

  • duanhuang7591 2013-07-08 08:29
    关注

    Why can't you do something like this ?

    <?php
      $i = 1;
      while($row=mysql_fetch_assoc($result))
      { ?>
        <tr id="row<?php echo $i;?>">
          <td id="cell-left-<?php echo $i;?>"><?php echo $row['col1'];?></td>
          <td id="cell-right-<?php echo $i;?>"><?php echo $row['col2'];?></td>
        </tr>
      <?php
         $i++;
       } ?>
    

    Please note, I have added ids row, cell-left- and cell-right- by myself. You may change them as per your requirements.

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

报告相同问题?

悬赏问题

  • ¥15 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加