dongtuoji5396 2011-08-16 14:56
浏览 83
已采纳

用数字标记HTML表的每一行(PHP + MYSQL)

All I want is for the first column of each row in my table to display the number of the current row. For example, please see the following table.

Column Header 1    Column Header 2
1                     some data
2                     more data
3                     some more data
4                     even more data

I am familiar with JavaScript (I will most likely understand any JS script posted), CSS, and HTML. I am curious as to whether or not I will have to write a JS function to do this, or if I can somehow just create a variable and increase its index by ' 1 ' each time.

I look forward to your responses!

  • 写回答

4条回答 默认 最新

  • dongwenxiu5200 2011-08-16 15:09
    关注

    If you're using PHP, try to get an array of strings for data you want to output:

    $data = array('here', 'is', 'some', 'data');
    
    // Avoid printing table if there is no data
    if (count($data) > 0) {
        echo '<table><tr><td>Column Header 1</td><td>Column Header 2</td></tr>';
        for ($i = 0; $i < count($data); $i++) {
            echo '<tr><td>', $i + 1, '</td><td>', $data[$i], '</td></tr>';
        }
        echo '</table>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致