[英]count how many rows in database and display them
I developed quiz application in PHP . 我用PHP开发了测验应用程序。 i have questions table in my database..so i display only one question per page.so when user click on next button i display next question from my database randomly..
我的数据库中有问题表。所以每页只显示一个问题。因此,当用户单击下一步按钮时,我会随机显示数据库中的下一个问题。
So the problem is when user reached to last question i want to change the button name to finish automatically without click on the button. 所以问题是当用户到达最后一个问题时,我想更改按钮名称以自动完成而无需单击按钮。
For Example: if i have 10 questions in my database when user reached 9th question and click on next button we need to display 10th question button as finish instead of next. 例如:如果我的数据库中有10个问题,当用户到达第9个问题并单击“下一步”按钮时,我们需要显示“第10个问题”按钮作为完成,而不是下一个。
How to do this? 这个怎么做?
This is my count Query: 这是我的计数查询:
$nRows = $dbh->query('select count(*) from questions')->fetchColumn();
echo $nRows;
This is my next button: 这是我的下一个按钮:
<button class="submit-btn Next"
id="refreshButton"
data-id="<?php echo $value->id ?>"
name="<?php echo $key ?>"
onclick="change_next(this.value)"
value="<?php echo $key ?>">
Next
</button>
you can keep a separate counter to count questions displayed. 您可以单独设置一个计数器来对显示的问题进行计数。
simple algo: 简单算法:
eg : questions = 10 #consider
counter = 1
while counter != questions:
displayquestion_using_random_function();
counter = counter + 1
if counter == questions:
change_the_button_to_finish()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.