javascript - 计算数据库中的行数

标签 javascript php jquery ajax

我的数据库中有一些问题。我每页仅显示一个问题,并带有“下一步”按钮。当用户单击“下一步”按钮时,我会随机显示数据库中的下一个问题。

所以问题是当用户到达最后一个问题时我想将“NEXT”按钮名称更改为“FINISH”。

请帮助我如何做到这一点..

this is my count query:
$nRows = $dbh->query('select count(*) from questions')->fetchColumn(); 
echo $nRows;

这是我的应用程序中的下一个按钮。

<button  id='Next'  class="next-button" name="submit_<?php echo $key ?>" value="<?php echo $key ?>" onclick="change_next(this.value)">Next</button>

这是我的 Java 脚本代码,用于每页显示一个问题:

<script type="text/javascript">

         function change_next(value) 
    {
    if(value == 0) 
    {
         var next = value;
         next++;

        $('#question_'+value).removeClass('active').addClass('hidden');
        $('#question_'+next).removeClass('hidden').addClass('active');
    } 
    else 
    {
        var next = value;
        next++;

        $('#question_'+value).removeClass('active').addClass('hidden');
        $('#question_'+next).removeClass('hidden').addClass('active');
    }
}

最佳答案

您只需更改按钮的值

    var count = 0;
    function change_next() {
      var xhttp = new XMLHttpRequest();
      xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          document.getElementById("Question").innerHTML = this.responseText;
          if (count == 5) {
             //document.getElementById("Next").value="FINISH";  <--sorry this is if you are using <input type="button" not button =/
             document.getElementById("Next").innerHTML="FINISH";
          }
          count++;
        }
      };
      xhttp.open("GET", "Load_Question.php", true);
      xhttp.send();
    }

关于javascript - 计算数据库中的行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41826548/

相关文章:

javascript - 使用 jQuery 动态添加/删除搜索过滤器

javascript - 我的代码在 Firefox 中不起作用...?

c# - 如何在给定视频 ID 的情况下获取 youtube channel ID 和名称

javascript - jquery中基于razor循环的循环

javascript - Jquery:如何突出显示选中的单选按钮 block

javascript - 获取当前模块脚本的 URL

PHP 将字符串转换为 slug

PHP mkdir 权限

jquery - Angular.js 内联编辑

jquery - 函数中变量的增量(jQuery)