Php 如何在ajax中使用First-Next-Previous-Last按钮从mysql中逐个访问详细信息?
我制作了一个id为的问题数据库。现在我使用ajax访问mysql数据库问题,使用First-Next-Previous-Last按钮逐个访问。怎么做。这是我的密码 index.phpPhp 如何在ajax中使用First-Next-Previous-Last按钮从mysql中逐个访问详细信息?,php,javascript,mysql,ajax,Php,Javascript,Mysql,Ajax,我制作了一个id为的问题数据库。现在我使用ajax访问mysql数据库问题,使用First-Next-Previous-Last按钮逐个访问。怎么做。这是我的密码 index.php var-str; 函数showid(str) { 如果(str==“”) { document.getElementById(“txtHint”).innerHTML=“”; 返回; } if(window.XMLHttpRequest) {//IE7+、Firefox、Chrome、Opera、Safari的代
var-str;
函数showid(str)
{
如果(str==“”)
{
document.getElementById(“txtHint”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“request.php?q=“+str,true”);
xmlhttp.send();
}
请求的数据
请求页面
尝试使用javascript设置当前问题编号,然后从那里开始工作
<script type="text/javascript">
var str;
var current_question = 1;
function showQuestion(_direction)
{
if(_direction == 'prev') current_question--;
else if(_direction == 'next') current_question++;
else if(_direction == 'first') current_question = 1;
else if(_direction == 'last') current_question = ?; // use php to set this when producing page
//...
xmlhttp.open("GET","question.php?q="+current_question,true);
xmlhttp.send();
var-str;
var当前问题=1;
函数showQuestion(_方向)
{
如果(_direction=='prev')当前的_问题--;
如果(_direction=='next')当前_问题++;
如果(_direction=='first')当前问题=1;
else如果(_direction=='last')当前_question=?;//在生成页面时使用php设置此选项
//...
open(“GET”,“question.php?q=“+current_question,true”);
xmlhttp.send();
然后像这样改变你的输入
<input type="button" value="|<" name="First" onClick="showQuestion('first')" />
<input type="button" value="<" name="Previous" onClick="showQuestion('prev')" />
<input type="button" value=">" name="Next" onClick="showQuestion('next')" />
<input type="button" value=">|" name="Last" id="Last" onClick="showQuestion('last')" />
这里我想为first next prev last按钮动态传递showQuestion函数中的值问题是什么:有错误或响应不正确?谢谢。响应中没有错误..但我想将值动态传递给showQuestion()基于下一个和上一个按钮逻辑的函数。注意:在问题.php
文件中不需要while循环,因为我想只有一条记录与ID
@Mahfuz匹配。没问题,如果这解决了您的问题,您可以将我的答案标记为完成或投票
<script type="text/javascript">
var str;
var current_question = 1;
function showQuestion(_direction)
{
if(_direction == 'prev') current_question--;
else if(_direction == 'next') current_question++;
else if(_direction == 'first') current_question = 1;
else if(_direction == 'last') current_question = ?; // use php to set this when producing page
//...
xmlhttp.open("GET","question.php?q="+current_question,true);
xmlhttp.send();
<input type="button" value="|<" name="First" onClick="showQuestion('first')" />
<input type="button" value="<" name="Previous" onClick="showQuestion('prev')" />
<input type="button" value=">" name="Next" onClick="showQuestion('next')" />
<input type="button" value=">|" name="Last" id="Last" onClick="showQuestion('last')" />