Organizational Research By

Surprising Reserch Topic

php sample script for pagination


php sample script for pagination  using -'php,mysql'

asked Oct 19, 2015 by 20shahi
0 votes
4 views



Related Hot Questions

5 Answers

0 votes

Following link can help you, its has easy to use description too

http://www.strangerstudios.com/sandbox/pagination/diggstyle.php

If you would like to have a tutorial then you should read on

answered Oct 19, 2015 by abhimca2006
0 votes

A plain and simple one in purpose to learn from

 $v) {
    if ($k != "page") $uri.=urlencode($k)."=".urlencode($v)."&";
  }
}

//getting total number of pages and filling an array with links
$num_pages=ceil($total_rows/$per_page);
for($i=1;$i<=$num_pages;$i++) $PAGES[$i]=$uri.'page='.$i;

//and here goes a simple template
?>
Total records: 

$row): ?> .

Pages: $link): ?>
answered Oct 19, 2015 by virendra.bajaj
0 votes

This isn't hard to do. Here's a recipe for a quick & simple system:

  1. Do the SELECT query, add the clause LIMIT PERPAGE*(PAGENUM-1),PERPAGE Note that the all in caps variables could be GET parameters to your script.

  2. Find the total number of results for your SELECT query if there wasn't a LIMIT clause (there are methods to do this, for instance, MySQL's SELECT "SQL_CALC_FOUND_ROWS * FROM . . .", which would be integrated into #1.) Call this N

  3. Display to the user the data, along with "Showing items PERPAGE*(PAGENUM-1)+1 to PERPAGE*PAGE of N"

I would post an example, but my queries and DB handle are handled elsewhere in my code.

answered Oct 19, 2015 by rajeshujade
0 votes

Although the guide is in Danish, I believe you can easily understand and use the abstract class from this site: http://www.jensgram.dk/web/e-artikler/1265 (near the bottom).

All you need to do is implement the renderItem() method and you're off:

class PaginatedGuestbook extends Paginator {
    protected function renderItem(&$row) {
        $o = "\Post from " . $row['name'] . "
\n" . "Header: " . $row['header'] . "
\n" . "Text: " . $row['body'] . "
\n"; // You can do whatever you want with the $row array return $o; } } $gb = new PaginatedGuestbook( 'guestbook_table', // Table(s) 'tstamp, name, header, body', // Fields to populate in renderItem's $row 'hidden=0 AND deleted=0', // Condition 'tstamp DESC', // Ordering 5 // Items per page ); print $gb->renderItems(); print "
\n\n"; print $gb->renderNavigation('paginated.php');

Furthermore, you can customize links etc.

answered Oct 19, 2015 by mca.agarwal
0 votes

i got a good pagination example:

   1)
    {   
        $pagination .= "
"; //previous button if ($page > 1) $pagination.= "« previous"; else $pagination.= "« previous"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "$counter"; else $pagination.= "$counter"; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "$counter"; else $pagination.= "$counter"; } $pagination.= "..."; $pagination.= "$lpm1"; $pagination.= "$lastpage"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "1"; $pagination.= "2"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "$counter"; else $pagination.= "$counter"; } $pagination.= "..."; $pagination.= "$lpm1"; $pagination.= "$lastpage"; } //close to end; only hide early pages else { $pagination.= "1"; $pagination.= "2"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "$counter"; else $pagination.= "$counter"; } } } //next button if ($page < $counter - 1) $pagination.= "next »"; else $pagination.= "next »"; $pagination.= "
\n"; } ?>

//////////////////////////////////////STYLE//////////////////////////////////////

    div.pagination {
    padding: 3px;
    margin: 3px;
}

div.pagination a {
    padding: 2px 5px 2px 5px;
    margin: 2px;
    border: 1px solid #AAAADD;

    text-decoration: none; /* no underline */
    color: #000099;
}
div.pagination a:hover, div.pagination a:active {
    border: 1px solid #000099;

    color: #000;
}
div.pagination span.current {
    padding: 2px 5px 2px 5px;
    margin: 2px;
        border: 1px solid #000099;

        font-weight: bold;
        background-color: #000099;
        color: #FFF;
    }
    div.pagination span.disabled {
        padding: 2px 5px 2px 5px;
        margin: 2px;
        border: 1px solid #EEE;

        color: #DDD;
    }
answered Oct 19, 2015 by deven.bendale

...