Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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>";

Solution 2:

You could try LIMIT in the sql query.

Pass on the LIMIToffset and limit in the URL and process/show the data accordingly & send back the current offset and limit to the web page(so that you could make url for the show more link)

I think this is how it is implemented at most of the places and frameworks

Sandeep

Solution 3:

in query use

SELECT list_of_column FROMtableORDERBY column_id DESC
 LIMIT 20OFFSET0

simply change the offset value for every click, you will get desired result

pagination in php, refer,

Solution 4:

In the MysqlQuery, you can use the LIMIT begin, max function: SELECT * FROM db LIMIT 100, 10 will select 10 data-sets beginning at offset 10.

You have to pass a $_GET or $_POST variable via javascript to the php script:

$.ajax({
    [...],
    url: "script.php",
    data: {
        page: <pagetoload>
    },
    [...]
})

In the php script you modify the query now:

$query = "SELECT * FROM database LIMIT " . $_GET['page'] . ", " . $entrys_per_page;

Post a Comment for "On Request Pagination(paginate Records On Demand Of User)"