Jump to content

Pagination Page numbering help


shortysbest

Recommended Posts

So I'm trying to get my pagination script to work so the url can be www.mysite.com/index.php?node=photos&page=2. However now how i have it it displays next to &page=(here) the row number that it starts at ie. &page=15  if number of rows per page is 15 and i am on page 2. then page 3 would be &page=30. So i haven't quite figured out how to do it, and i haven't got enough time to mingle with it so i was hoping i could get some quick help on this.

 

Another thing i would like to do is put "..." between pages when there is a lot, like, more than 10 pages. IE.  the page numbering spot would like similar to this

 

<<1 2 3 4 5 ... 20 21 22 >>

 

my code is:

//max displayed per page
$per_page = 15;
//get start variable
$start = $_GET['page'];
//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM antiques "));
//count max pages
$max_pages = $recordcount / $per_page; //may come out as decimal

if (!$start)
$start = 0;
//display data
$query1 = mysql_query("SELECT * FROM antiques ORDER BY id DESC LIMIT $start, $per_page");	
$result = mysql_query("SELECT * FROM antiques");
$num_rows = mysql_num_rows($result);
print '<h5>Our Antiques <em>('.$num_rows.')</em></h5><p>';
//seetup prev and next variables
$previous = $start - $per_page;
$next = $start + $per_page;
//show previous button
//show page numbers
//set variable for first page
if (!($record_count<$per_page))
print '<div class="antiquespagecontainer">';
$i=1;
if (!($start<=0))
print "<a class='pages' href='index.php?node=antiques&page=$previous'>Previous</a> ";
else if (!($record_count<$per_page))
{
print "<a class='pagesinnactive'>Previous</a> ";
}
//show page numbers
for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
print "<a class='pages' href='index.php?node=antiques&page=$x'>$i</a> ";
else if (!($record_count<$per_page))
echo "<a class='pages_current'>$i</a> ";
$i++;
}
//show next button
if (!($start>=$record_count-$per_page))
{
print "<a class='pages' href='index.php?node=antiques&page=$next'>Next</a>";
}
else if (!($record_count<$per_page))
{
print "<a class='pagesinnactive'>Next</a>";
}
if (!($record_count<$per_page))
print '</div><p>';
print '<div class="antiquesconstrainer">';

 

Thanks in advanced

Link to comment
https://forums.phpfreaks.com/topic/205712-pagination-page-numbering-help/
Share on other sites

$next = $start + $per_page; 

Don't have $next have anything to do with the $per_page variable. Just set it to $_GET['page'] + 1;

$start should be equal to $_GET['page'] * $per_page

 

As for the second request first say exactly what you want to do. So if there is more than 10 pages would want to display ....

but you want to display the last three pages available when doing this?  If there is only 13 pages do you want to display all of them? Or shorten the

requirement for the "...". It's not too difficult to code but narrow down the specifics for the logic first.

$next = $start + $per_page; 

Don't have $next have anything to do with the $per_page variable. Just set it to $_GET['page'] + 1;

$start should be equal to $_GET['page'] * $per_page

 

As for the second request first say exactly what you want to do. So if there is more than 10 pages would want to display ....

but you want to display the last three pages available when doing this?  If there is only 13 pages do you want to display all of them? Or shorten the

requirement for the "...". It's not too difficult to code but narrow down the specifics for the logic first.

 

Yeah, I coded the first part myself, was easy to do. just had to change a few of the variables to work together. just had put $_GET['page']*$per_page-$per_page and that does the trick. And as to the ... request, i know i could code it myself relatively easy however i've been busy with other things preparing the site to go live in 2 more days and haven't got the spare time to mess with these little things.

 

I just want it if there is more than, let's just go with more than 10 pages, but let's say the amount of pages is 20. I would like to have the page numbering system to look like this:

 

Previous 1 2 3 ... 18 19 20 Next  That would be when you're on page one. However let's say you're on page 10.

 

Previous 8 9 10 ... 18 19 20 Next

 

Also if there is less or equal to 10 pages i just want it to be normal like

 

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

 

Once i get this to work I am going to add a First & Last to it as well.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.