donglu3243 2015-05-23 13:27
浏览 5

显示网页上mysql表的每一行的“运行时间”

I have now a table in mysql that I push out every 3:rd second but I will try to push it out only when the table is updated. I use node.js for this but my first priority now is to have a "time since added at the end of the row for each record that I show (max 20 records). Here is a part of my script on my server side (nodejs)

socket.on('notification', function (data) {
    var resultsList = "";
    resultsList += "<h1>Title</h1>";
    //resultsList += "<span id=\'ct\' ></span>";
    resultsList += "<table border='1'><tr>";
    resultsList += "<font size=18>";
    resultsList += "<td width=200> Column1</td><td width=100>Column2</td><td width =200>Column3</td>";
    $.each(data.results,function(index,result){
        resultsList += "<tr>" + "<td>" + result.Column1 + "</td>" + "<td>" + result.Column3.toFixed(2) + "</td><td>" + result.Column2 + "</td></tr>";
    });
    resultsList += "</tr>";
    $('#container').html(resultsList);
  });

I have a "result" table in mysql that I easily publish on a webpage but I would like to add a "timeSinceUpdated" column at the end for every row and the time shall tick while watching the webpage. I also want to have the webpage updated without the need for the users to do a refresh in their web browsers. What is the best approach?

  • 写回答

1条回答 默认 最新

  • doubinei1457 2015-05-23 13:33
    关注

    Hello and welcome on Stackoverflow.

    The best way to handle it is AJAX. On your page where video can be watched, you need to insert Javascript, which will run periodically and submit data to ie. ticker.php

    ticker.php will get id of the result table and increase the counter.

    I also want to have the webpage updated without the need for the users to do a refresh in their web browsers. What is the best approach?

    jQuery. Retrieve data using Ajax and put them on your page without reloading..

    In my opinion, those are the simplest solutions. Note, that ticker can be misused by malice user.

    评论

报告相同问题?

悬赏问题

  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥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 腾讯云如何建立同一个项目中物模型之间的联系