Javascript 统计数据库中的行数
我的数据库里有一些问题。我每页只显示一个带有“下一步”按钮的问题。当用户单击next按钮时,我随机显示数据库中的下一个问题 所以问题是,当用户遇到最后一个问题时,我想将“下一步”按钮名称更改为“完成” 请帮我怎么做Javascript 统计数据库中的行数,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我的数据库里有一些问题。我每页只显示一个带有“下一步”按钮的问题。当用户单击next按钮时,我随机显示数据库中的下一个问题 所以问题是,当用户遇到最后一个问题时,我想将“下一步”按钮名称更改为“完成” 请帮我怎么做 this is my count query: $nRows = $dbh->query('select count(*) from questions')->fetchColumn(); echo $nRows; 这是我应用程序中的下一个按钮 <button
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>
您只需更改按钮的值
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计数=0;
函数更改_next(){
var xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“问题”).innerHTML=this.responseText;
如果(计数=5){
//document.getElementById(“Next”).value=“FINISH”您只需更改按钮的值
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计数=0;
函数更改_next(){
var xhttp=newXMLHttpRequest();
xhttp.onreadystatechange=函数(){
if(this.readyState==4&&this.status==200){
document.getElementById(“问题”).innerHTML=this.responseText;
如果(计数=5){
//document.getElementById(“Next”).value=“FINISH”;如何在ajax中执行相同的操作当您执行调用“change\u Next”时-将上述代码添加到ajax调用返回中,这将在单击“Next”时更改按钮名称button,你可以用PHP随机加载一个问题,但你不想通过Ajax加载问题来加载你的页面,对吗?你有固定数量的问题吗?@nenroz no nennroz..我已经在页面上显示了问题,但没有刷新..我的问题是当我遇到最后一个问题时,我想将按钮名称更改为Finish.自动..在ajax中我们如何做同样的事情当您调用“更改\下一步”-将上述代码添加到ajax调用返回中,这将在您单击“下一步”时更改按钮名称button,你可以用PHP随机加载一个问题,但你不想通过Ajax加载问题来加载你的页面,对吗?你有固定数量的问题吗?@nenroz no nennroz..我已经在页面上显示了问题,但没有刷新..我的问题是当我遇到最后一个问题时,我想将按钮名称更改为Fini自动。。
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";
}