Q:

On request pagination(Paginate records on demand of user)

I am working on a grid which displays number of records,based on some filters. I want to paginate those,when the user clicks on a link Show More at the bottom of grid. I tried for a search but,either found the page number stuff or some kind of auto scroll. But,how can I get to work in my scenario? 
What my research till now is,I will have to write a function onclick of the link,fetch the next batch of records(say 20 on each request) using ajax. But how would the programing part work. I am using PHP at the server end and Mysql as my DB
Can someone guide me on it. Thanks for your time. 

A:

if(isset($_GET['page']))
{
    $page=$_GET['page'];
}
else
{
    $page=1;
}

if(isset($_GET['dark']))
{
    $max_result=$_GET['dark'];

}
else
{
    $max_result=5;
}

$from=(($page*$max_result)-$max_result);

mysql_select_db("db",$con);
$sql = "SELECT COUNT(*) FROM `db`. `table` ";
$result=mysql_query($sql);

$total_result=mysql_result($result,0);
$total_pages=ceil($total_result/$max_result);

if($total_result>$max_result)
{
    if($page>1)
    {
        $prev=$page-1;
        echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result. "&page=$prev\">previous</a>";
    }
    for($i=1;$i<=$total_pages;$i++)
    {
        if($page==$i)
        {
        echo "<strong>".$i. "</strong>";
        }
        else
        {
        echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result. "&page=$i\">$i</a> ";
        }
        if($page<$total_pages)
        {
        $next=$page+1;

        //echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";
        }
    }

        if($page<$total_pages)
        {
                $next=$page+1;
                echo "<a href=\"".$_SERVER['PHP_SELF']."?dark=".$max_result. "&page=$next\">next</a>";
        }
}

         echo "<table><tr>";

            echo "<td><form action='helloworld.php' name='get'>
                <select name='dark'>
                <option value='2'>2</option>
                <option value='5'>5</option>
                <option value='10'>10</option>
                </select>
                <input type='hidden' name='searching' value='yes' /><input type='submit' value='No.of entries'>
                </form></td></tr>";         
            echo "<tr><td><strong>PAGE NUMBER $page of $total_pages.</strong>.</td></tr>";
            echo"</table>";

