簡體   English   中英

計算數據庫中的行數

[英]count number of rows in database

我的數據庫中有一些問題。 我每頁僅顯示一個問題,並帶有“下一步”按鈕。 當用戶單擊下一步按鈕時,我會隨機顯示數據庫中的下一個問題。

所以問題是,當用戶遇到最后一個問題時,我想將“ 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();
    }
var count = 0;
function showNextQuestion() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      count+=1;
      if(count>=3) {
         document.getElementById("Next").innerHTML="Finish";
      }
    }
  };
  xhttp.open("GET", "QuestionLoader", true);
  xhttp.send();
}
<button  id='Next'  class="next-button" name="submit_<?php echo $key ?>" value="<?php echo $key ?>" onclick="change_next()">Next</button>

function change_next()
{
    document.getElementById("Next").value="FINISH"; 
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM