I have made a question database with id . Now i am using ajax to access the mysql database question one by one using First Next Previous Last button. How to do it. Here is my code.
index.php
<html>
<head>
<script type="text/javascript">
var str;
function showid(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","request.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body onLoad="showid(1)">
<br />
<div id="txtHint">Requested Data
</div>
<br />
<input type="button" value="Last" name="First" onClick="showid(1)" />
<input type="button" value="Previous" name="Previous" onClick="showid(2)" />
<input type="button" value=Next name="Next" onClick="showid(3)" />
<input type="button" value="First" name="Last" id="Last" onClick="showid(4)" />
</body>
</html>
requesting page
<?php
$q=$_GET["q"];
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbase", $con);
$sql="SELECT * FROM table WHERE id = '".$q."'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$id=$row['id'];
}
mysql_close($con);
?>
Try using javascript to set the current question number and work from there.
then change your inputs like so