doulun1939 2014-10-27 00:48
浏览 31


I have a db table with several fields and i want to make a countdown with the integer value of one of the fields (as minutes). How can i loop and display the countdown of each of those rows in a php table using these values and adding or subtracting time in the process if I need to?


            $sql="SELECT * FROM List where depName='Admisiones' and  personStatus='Espera'";
            $result=mysqli_query($con, $sql);

            echo "<table border='15' cellpadding='10' cellspacing='3' bordercolor='00FF00'>
            <th>Segundo Apellido</th>
            <th>Id Studiante</th>
            <th>Multiples Motivos</th>
            <th>Tiempo Categoria</th>
            <th>Tiempo Estimando</th>

            while($row = mysqli_fetch_array($result)) 
                echo "<tr>";
                echo "<td>" . $row['listNum'] . "</td>";
                echo "<td>" . $row['personName'] . "</td>";
                echo "<td>" . $row['personLast'] . "</td>";
                echo "<td>" . $row['secondLast'] . "</td>";
                echo "<td>" . $row['stuId'] . "</td>";
                echo "<td>" . $row['personStatus'] . "</td>";
                echo "<td>" . $row['manyMotive'] . "</td>";
                echo "<td>" . $row['categoryTime'] . "</td>";                                   
                echo "<td>" . $row['estimatedTime']"</td>"; //USE THE CLOCK.PHP TO MAKE A COUNTDOWN FOR EACH ESTIMATED TIME.
                //And have the ability to add or substrac time if needed.
                echo "</tr>";

            echo "</table>";


      var minutes = $(this).data('minutes');
      var count  = $(this); //countdown
      var id = $(this).id;
      date     : + (minutes * 60000),
      refresh  :  1000

      var minuteValue = count.text();
           url     : 'TEST.php', //I created to make the test..
           type    : 'POST',
           data    : {currentMin : minuteValue, id:id},
           success : function(response){




    include 'Connection.php';
        $minValue =  mysqli_real_escape_string($con,  $_POST['minuteValue']);
        $ID = mysqli_real_escape_string($con,  $_POST['id']);

        if (!$con) {
            die("Connection failed: " . mysqli_connect_error());

        $sql ="Update List SET estimatedTime='$minValue' WHERE listNum='$ID'";
  • 写回答

1条回答 默认 最新

  • doujia1988 2014-10-27 03:55

    OK, here's how I would do it. I would delete clock.php and use something more sophisticated. For example this js plugin:

    Download the file and include it in your <head> tag. Make sure you include jquery before that.

    Inside your table.php change this line:

    echo "<td>" . $row['estimatedTime']"</td>";


    echo "<td><div class=\'countdown\' data-minutes=\'{$row['categoryTime']}\' id=\{$row['id']'\'></div></td>";

    Basically your html for that countdown field has to look like this (PS:30 is dynamic number coming from 'categoryTime') :

    <td><div class="countdown" data-minutes="30" id="16"></div></td>

    In footer of that page or in your javascript file include this script:

          var minutes = $(this).data('minutes');
          var id = $(this).id;
             date     : + (minutes * 60000),
             refresh  :  60000
          var minuteValue = $(this).text();
                   url     : 'url/to/php/file', //php file that updates your DB. Take the values from POST VAR.
                   type    : 'POST',
                   data    : {currentMin : minuteValue, id:id},
                   success : function(response){

    With this, you will loop thru each .countdown element, get its minutes from data-minutes attr, and tell the countdown plugin when timer should expire by adding those minutes to value.

    EDIT after your comment:

    What you are looking for is node.js. That would be perfect for you. But I've updated the code anyways. It is not tested so I don't know if that's gonna work. It should be something like that. The only issue could (MAYBE) be in setting interval for each row in your table.


    • in php file, run query that updates rows in db
    • depending on your DB, see if you can get number of rows affected
    • if affected rows > 0, echo 1, otherwise echo 0
    • in Firebug (or similar) check the console message to see output of your php or any other errors

    This might help you find where the problem lies

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



    • ¥15 爬虫爬取安居客新房信息
    • ¥15 php5.3内存泄露
    • ¥15 DigSilent如何复制复合模型到自己案例?
    • ¥15 求日版华为b610s-77a 官方公版固件,有偿
    • ¥15 关于#java#的问题,请各位专家解答!(相关搜索:java程序)
    • ¥15 linux tsi721的驱动编译后 insmod 提示 报错
    • ¥20 multisim测数据
    • ¥15 求无向连通网的所有不同构的最小生成树
    • ¥15 模拟器的framebuffer问题
    • ¥15 opencv检测轮廓问题