Jump to content

Recommended Posts

Hi All

 

Im trying to get my Paganation to work, well it is working, just not how i want it to work...

 

atm it will list 2 records per page, then it will list the page numbers...

 

First Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 etc Next Last

 

My page numbers show every page, so when i have 100+pages it will show them all.

 

I would like to change my current code to something like the following:

 

1 2 3 4 5 6 7 8 9 10 - Next 10

Previous 10 - 11 12 13 14 15 16 17 18 19 20 - Next 10

 

below is my current code... i have only just started to learn PHP (2-3days ago) ive looked at aload of tutorials but still cant get my head around how to do it.

 

My Current Code:

if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; }; 
$start_from = ($page-1) * 2; 
$rs_result = @mysql_query("SELECT Count(idinfo) from info WHERE fldName LIKE '". $_GET['run'] . "%'");
$row1 = mysql_fetch_row($rs_result); 
$total_records = $row1[0]; 
$total_pages = ceil($total_records / 2); 

if ($total_pages == 1) {}
else {If ($page == 1) {}
else{
echo " <a href='index.html?run=". $_GET['run'] . "&page=1'> <<-First</a> ";
echo " ";
}
If ($page == 1) {}
else{
$previous = $page-1;
echo " <a href='index.html?run=". $_GET['run'] . "&$previous'> <-Previous</a> ";
} 
}
for ($i=1; $i<=$total_pages; $i++) { 

            echo "<a href='index.html?run=". $_GET['run'] . "&page=".$i."'>Page ".$i."</a> ";
}

if ($page == $total_pages) {

}
else {
$previous = $page+1;
echo " <a href='index.html?run=". $_GET['run'] . "&page=$previous'> Next-></a> ";
If ($page == $total_pages) {}
else{
echo " <a href='index.html?run=". $_GET['run'] . "&page=$total_pages'> Last->></a> ";
} 
}
		echo ("<br> Page $page of $total_pages<br><br>");
}

 

There is probably better ways to code this in, but it works like this so i am happy :)

 

Any help will be great.

 

Thanks

-Dream

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/229320-paganation/
Share on other sites

2-3 days ago, and already working with pagination? Do you have previous programming experience or are you a fast learner? lol

 

Anyway, I've started learning PHP 2 month ago, with no previous programming experience.

 

And I've build a great working pagination with the help of this forum.

 

Check out this tutorial on PHPFreaks, if you haven't done already: http://www.phpfreaks.com/tutorial/basic-pagination

 

It is kept simple which is great for learning. It also showcases in that tutorial, how to do what you're trying to accomplish, just look at the part where it's saying how to showcase the 3 previous and next pages.

Link to comment
https://forums.phpfreaks.com/topic/229320-paganation/#findComment-1181601
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.