title: How to access details one by one from mysql using First Next Previous Last button with ajax?
body: <p>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.</p>
  
  <h1>index.php</h1>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;script type="text/javascript"&gt;
  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 &amp;&amp; xmlhttp.status==200)
      {
      document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
  
      }
    }
  xmlhttp.open("GET","request.php?q="+str,true);
  xmlhttp.send();
  }
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onLoad="showid(1)"&gt;
  
  &lt;br /&gt;
  &lt;div id="txtHint"&gt;Requested Data
  &lt;/div&gt;
  &lt;br /&gt;
  
  &lt;input type="button" value="Last" name="First" onClick="showid(1)"  /&gt;
  &lt;input type="button" value="Previous" name="Previous" onClick="showid(2)"  /&gt;
  &lt;input type="button" value=Next name="Next" onClick="showid(3)"  /&gt;
  &lt;input type="button" value="First" name="Last" id="Last" onClick="showid(4)"  /&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h1>requesting page</h1>
  
  <pre><code>&lt;?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);
  
  
  
  ?&gt;
  </code></pre>