Jump to content

Google like php pagination


zohab

Recommended Posts

Hi,

 

I have pagination code and i have taken this code from

 

http://www.plus2net.com/php_tutorial/demo_paging4.php

 

Now in my project i have records more than 1000 and i am showing 5 records per page.

 

So total pages are 190.This is disturbing page layout as per shown in image.

 

I want google like pagination

 

I want to show pages 1 2 3 4 5 6 7 8 9 10 Next

When user click on Next then 2 3 4 5 6 7 8 9 Next

When user click on Prev then 1 2 3 4 5 6 7 8 9  10 Next

When user click on page number then that page record will be shown.

I have attached zip file containing all pages required for pagination with an example.

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

Hi gwolgamott,

 

thanks for advance php pagination site url.

 

but it is not providing paginationthe way google provides.

 

I want to show pages 1 2 3 4 5 6 7 8 9 10 Next

 

1.When user click on Next then 2 3 4 5 6 7 8 9 Next

2.When user click on Prev then 1 2 3 4 5 6 7 8 9  10 Next

3.When user click on page number then that page record will be shown.

 

Link to comment
Share on other sites

Ah, well that is a bit more obtrusive to do. Can it be done yeah, but way too much time to do it for me unless I needed it. But if you understand php that sample code is a start and just change the action of the next link instead with perhaps a series of if statements that check current and next page of links...

 

Here's a script that uses a database first to pull rows, but if you don't want to use that then it's not hard to retro-fit to your needs. I had this sitting someplace, and have forgotten where i got it from. I didn't write it so can't go through it in detail (Well I could, but it's not as easy if I wrote it.), but they may be a better start for you with already working on the other script too.

 


<?php

$limit = 10;
$start = 1;
$slice = 9;

$q = "SELECT * FROM table";
$r = mysql_query($q, conn());
$totalrows = mysql_num_rows($r);

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

$numofpages = ceil($totalrows / $limit);
$limitvalue = $page * $limit - ($limit);

$q = "SELECT * FROM table LIMIT $limitvalue, $limit";
if ($r = mysql_query($q, conn())) {

//loop results here
while ($row = mysql_fetch_assoc($r)) {
echo $row['column'].'<br />';
}

if($page!= 1){
$pageprev = $page - 1;
echo '<a href="'.$_SERVER['php_SELF'].'?page='.$pageprev.'">PREV</a> - ';
}else{
echo "PREV - ";
}

if (($page + $slice) < $numofpages) {
$this_far = $page + $slice;
} else {
$this_far = $numofpages;
}

if (($start + $page) >= 10 && ($page - 10) > 0) {
$start = $page - 10;
}

for ($i = $start; $i <= $this_far; $i++){
if($i == $page){
echo "<u><b>".$i."</b></u> ";
}else{
echo '<a href="'.$_SERVER['php_SELF'].'?page='.$i.'">'.$i.'</a> ';
}
}

if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page + 1;
echo ' - <a href="'.$_SERVER['php_SELF'].'?page='.$pagenext.'">NEXT</a>';
}else{
echo " - NEXT";
}

}

?> 

Link to comment
Share on other sites

Thanks gwolgamott,

 

Great work  :D

 

I am sorry but my project manager change the requirement.

 

Now he want pagination functionality as follows.

 

Suppose we have 30 pages ,we have to show 5 records per page

 

Page 1 will show : 1 2 3 4 5 Next5

Page 2 will show : Prev5  6 7 8 9 10 Next5

Page 3 will show : Prev5  11 12 13 14 15 Next5

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.