Php表中的Javascript倒计时显示

Php表中的Javascript倒计时显示,javascript,php,html,database,Javascript,Php,Html,Database,我有一个包含多个字段的db表,我想用其中一个字段的整数值(以分钟为单位)进行倒计时。如果需要,我如何使用这些值循环并显示php表中每一行的倒计时,并在过程中添加或减去时间 Table.php $sql="SELECT * FROM List where depName='Admisiones' and personStatus='Espera'"; $result=mysqli_query($con, $sql); ec

我有一个包含多个字段的db表,我想用其中一个字段的整数值(以分钟为单位)进行倒计时。如果需要,我如何使用这些值循环并显示php表中每一行的倒计时,并在过程中添加或减去时间

Table.php

            $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'>
            <tr>
            <th>Turno</th>
            <th>Nombre</th>
            <th>Apellido</th>
            <th>Segundo Apellido</th>
            <th>Id Studiante</th>
            <th>Status</th>
            <th>Multiples Motivos</th>
            <th>Tiempo Categoria</th>
            <th>Tiempo Estimando</th>
            </tr>";

            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>";
      <script>
      $('.countdown').each(function(){
      var minutes = $(this).data('minutes');
      var count  = $(this); //countdown
      var id = $(this).id;
      $(this).countdown({
      date     :  Date.now() + (minutes * 60000),
      refresh  :  1000
      });

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

          });
       });
    });
    <?php

    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'";
        mysqli_query($con,$sql);
        mysqli_close($con);
    ?>
$sql=“从depName='adminions'和personStatus='Espera'所在的列表中选择*;
$result=mysqli\u查询($con,$sql);
回声“
图尔诺
名义
阿佩利多
塞贡多阿佩利多
学生证
地位
多重动机
提姆波分类酒店
蒂恩波埃斯蒂曼多酒店
";
while($row=mysqli\u fetch\u数组($result))
{
回声“;
回显“$row['listNum']”;
回显“$row['personName']”;
回显“$row['personLast']”;
回显“$row['secondLast']”;
回显“$row['stuId']”;
回显“$row['personStatus'”;
回显“$row['manyMotive']”;
回显“$row['categoryTime]”;
echo“$row['estimatedTime']”;//使用CLOCK.PHP对每个估计时间进行倒计时。
//如果需要的话,还可以添加或取消跟踪时间。
回声“;
}
回声“;
Clock.php

            $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'>
            <tr>
            <th>Turno</th>
            <th>Nombre</th>
            <th>Apellido</th>
            <th>Segundo Apellido</th>
            <th>Id Studiante</th>
            <th>Status</th>
            <th>Multiples Motivos</th>
            <th>Tiempo Categoria</th>
            <th>Tiempo Estimando</th>
            </tr>";

            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>";
      <script>
      $('.countdown').each(function(){
      var minutes = $(this).data('minutes');
      var count  = $(this); //countdown
      var id = $(this).id;
      $(this).countdown({
      date     :  Date.now() + (minutes * 60000),
      refresh  :  1000
      });

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

          });
       });
    });
    <?php

    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'";
        mysqli_query($con,$sql);
        mysqli_close($con);
    ?>

$('.countdown')。每个(函数(){
var minutes=$(this.data('minutes');
var count=$(this);//倒计时
var id=$(this).id;
$(本页)。倒计时({
日期:date.now()+(分钟*60000),
刷新次数:1000
});
设置间隔(函数(计数)
var minuteValue=count.text();
$.ajax({
url:'TEST.php',//我创建它是为了进行测试。。
键入:“POST”,
数据:{currentMin:minuteValue,id:id},
成功:功能(响应){
控制台日志(响应);
}
});
});
});
TEST.php

            $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'>
            <tr>
            <th>Turno</th>
            <th>Nombre</th>
            <th>Apellido</th>
            <th>Segundo Apellido</th>
            <th>Id Studiante</th>
            <th>Status</th>
            <th>Multiples Motivos</th>
            <th>Tiempo Categoria</th>
            <th>Tiempo Estimando</th>
            </tr>";

            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>";
      <script>
      $('.countdown').each(function(){
      var minutes = $(this).data('minutes');
      var count  = $(this); //countdown
      var id = $(this).id;
      $(this).countdown({
      date     :  Date.now() + (minutes * 60000),
      refresh  :  1000
      });

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

          });
       });
    });
    <?php

    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'";
        mysqli_query($con,$sql);
        mysqli_close($con);
    ?>

好的,我会这样做。我会删除clock.php并使用更复杂的东西。例如,这个js插件:

下载文件并将其包含在
标记中。确保在此之前包含jquery

在您的table.php中更改此行:

echo "<td>" . $row['estimatedTime']"</td>";
echo”“$行['estimatedTime']”;
致:

echo”“;
基本上,该倒计时字段的html必须如下所示(PS:30是来自“categoryTime”的动态数字):


在该页面的页脚或javascript文件中包含以下脚本:

<script>
   $('.countdown').each(function(){
      var minutes = $(this).data('minutes');
      var id = $(this).id;
      $(this).countdown({
         date     :  Date.now() + (minutes * 60000),
         refresh  :  60000
      });

      var minuteValue = $(this).text();
      setInterval(function(){

           $.ajax({
               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){
                   console.log(response);
               }

           });
      });
   });



</script>

$('.countdown')。每个(函数(){
var minutes=$(this.data('minutes');
var id=$(this).id;
$(本页)。倒计时({
日期:date.now()+(分钟*60000),
刷新:60000
});
var minuteValue=$(this.text();
setInterval(函数(){
$.ajax({
url:'url/to/php/file',//更新数据库的php文件。从POST VAR中获取值。
键入:“POST”,
数据:{currentMin:minuteValue,id:id},
成功:功能(响应){
控制台日志(响应);
}
});
});
});
这样,您将循环遍历每个.countdown元素,从data minutes attr获取其分钟数,并通过将这些分钟数添加到Date.now()值来告诉倒计时插件计时器何时到期

评论后编辑:

您要查找的是node.js。那对你来说太完美了。但我已经更新了代码。它没有经过测试,所以我不知道这是否有效。应该是这样的。唯一的问题可能(可能)是为表中的每一行设置间隔

EDIT2

  • 在php文件中,运行更新数据库中的行的查询
  • 根据您的数据库,查看是否可以获得受影响的行数
  • 如果受影响的行>0,则回显1,否则回显0
  • 在Firebug(或类似)中,检查控制台消息以查看php的输出或任何其他错误

这可能会帮助您找到问题所在

您想做什么还不清楚。你能发布一些代码并澄清你的问题吗?我有我所需要的一切,我只需要一种方法来实现它,这样时钟就会从
$row['categoryTime']
中获取值,并在
$row['estimatedTime']
行中倒计时。我不知道
$row['categoryTime']
中有什么内容,但如果我正确理解你的评论,您需要将其传递给countDownTime函数。所以它看起来是这样的:
countdown()并使用该数据进行倒计时。我将脚本标记放在php标记之外,但如果更简单的话,您可以使用concat。仍然无法100%确定我是否完全理解您的想法。
$row['categoryTime']
中有一个类似于30的整数。但是脚本函数没有参数…如果我这样做,我会工作吗?如果是的话,你能给我一个例子,让我在函数中捕捉到这个变量吗。你能帮我把这两种语言混合在一起,这样它就可以工作了吗。现在,我想知道是否有一种方法每次倒计时刷新时,我都可以将值存储在db中的该字段中?我也更新了代码,我照你说的做了,但它没有更新。看看你是否按照我上面提到的步骤来试着查找错误我找到了变量$\u POST的错误它们都是空的。我使用整数值来测试它,并且查询可以工作。控制台的输出为第一行的
00小时、07分钟和28秒。在第二秒钟,当lo时,id变为2等