Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
I'm looking for an example algorithm of smart pagination. By smart, what I mean is that I only want to show, for example, 2 adjacent pages to the current page, so instead of ending up with a ridiculously long page list, I truncate it.
Here's a quick example to make it clearer... this is what I have now:
Pages: 1 2 3 4 [5] 6 7 8 9 10 11
This is what I want to end up with:
Pages: ... 3 4 [5] 6 7 ...
(In this example, I'm only showing 2 adjacent pages to the current page)
I'm implementing it in PHP/Mysql, and the "basic" pagination (no trucating) is already coded, I'm just looking for an example to optimize it... It can be an example in any language, as long as it gives me an idea as to how to implement it...
Here is some code based on original code from this very old link. It uses markup compatible with Bootstrap's pagination component, and outputs page links like this:
[1] 2 3 4 5 6 ... 100
1 [2] 3 4 5 6 ... 100
...
1 2 ... 14 15 [16] 17 18 ... 100
...
1 2 ... 97 [98] 99 100
<?php
// How many adjacent pages should be shown on each side?
$adjacents = 3;
//how many items to show per page
$limit = 5;
// if no page var is given, default to 1.
$page = (int)$_GET["page"] ?? 1;
//first item to display on this page
$start = ($page - 1) * $limit;
/* Get data. */
$data = $db
->query("SELECT * FROM mytable LIMIT $start, $limit")
->fetchAll();
$total_pages = count($data);
/* Setup page vars for display. */
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages / $limit);
//last page minus 1
$lpm1 = $lastpage - 1;
$first_pages = "<li class='page-item'><a class='page-link' href='?page=1'>1</a></li>" .
"<li class='page-item'><a class='page-link' href='?page=2'>2</a>";
$ellipsis = "<li class='page-item disabled'><span class='page-link'>...</span></li>";
$last_pages = "<li class='page-item'><a class='page-link' href='?page=$lpm1'>$lpm1</a></li>" .
"<li class='page-item'><a class='page-link' href='?page=$lastpage'>$lastpage</a>";
$pagination = "<nav aria-label='page navigation'>";
$pagincation .= "<ul class='pagination'>";
//previous button
$disabled = ($page === 1) ? "disabled" : "";
$pagination.= "<li class='page-item $disabled'><a class='page-link' href='?page=$prev'>« previous</a></li>";
//pages
//not enough pages to bother breaking it up
if ($lastpage < 7 + ($adjacents * 2)) {
for ($i = 1; $i <= $lastpage; $i++) {
$active = $i === $page ? "active" : "";
$pagination .= "<li class='page-item $active'><a class='page-link' href='?page=$i'>$i</a></li>";
}
} elseif($lastpage > 5 + ($adjacents * 2)) {
//enough pages to hide some
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2)) {
for ($i = 1; $i < 4 + ($adjacents * 2); $i++) {
$active = $i === $page ? "active" : "";
$pagination .= "<li class='page-item $active'><a class='page-link' href='?page=$i'>$i</a></li>";
}
$pagination .= $ellipsis;
$pagination .= $last_pages;
} elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
//in middle; hide some front and some back
$pagination .= $first_pages;
$pagination .= $ellipsis
for ($i = $page - $adjacents; $i <= $page + $adjacents; $i++) {
$active = $i === $page ? "active" : "";
$pagination .= "<li class='page-item $active'><a class='page-link' href='?page=$i'>$i</a></li>";
}
$pagination .= $ellipsis;
$pagination .= $last_pages;
} else {
//close to end; only hide early pages
$pagination .= $first_pages;
$pagination .= $ellipsis;
$pagination .= "<li class='page-item disabled'><span class='page-link'>...</span></li>";
for ($i = $lastpage - (2 + ($adjacents * 2)); $i <= $lastpage; $i++) {
$active = $i === $page ? "active" : "";
$pagination .= "<li class='page-item $active'><a class='page-link' href='?page=$i'>$i</a></li>";
}
}
}
//next button
$disabled = ($page === $last) ? "disabled" : "";
$pagination.= "<li class='page-item $disabled'><a class='page-link' href='?page=$next'>next »</a></li>";
$pagination .= "</ul></nav>";
if($lastpage <= 1) {
$pagination = "";
}
echo $pagination;
foreach ($data as $row) {
// display your data
}
echo $pagination;
Kinda late =), but here is my go at it:
function Pagination($data, $limit = null, $current = null, $adjacents = null)
{
$result = array();
if (isset($data, $limit) === true)
{
$result = range(1, ceil($data / $limit));
if (isset($current, $adjacents) === true)
{
if (($adjacents = floor($adjacents / 2) * 2 + 1) >= 1)
{
$result = array_slice($result, max(0, min(count($result) - $adjacents, intval($current) - ceil($adjacents / 2))), $adjacents);
}
}
}
return $result;
}
Example:
$total = 1024;
$per_page = 10;
$current_page = 2;
$adjacent_links = 4;
print_r(Pagination($total, $per_page, $current_page, $adjacent_links));
Output (# Codepad):
Array
(
[0] => 1
[1] => 2
[2] => 3
[3] => 4
[4] => 5
)
Another example:
$total = 1024;
$per_page = 10;
$current_page = 42;
$adjacent_links = 4;
print_r(Pagination($total, $per_page, $current_page, $adjacent_links));
Output (# Codepad):
Array
(
[0] => 40
[1] => 41
[2] => 42
[3] => 43
[4] => 44
)
I started from the lazaro's post and tried to make a robust and light algorithm with javascript/jquery...
No additional and/or bulky pagination libraries needed...
Look on fiddle for an live example: http://jsfiddle.net/97JtZ/1/
var totalPages = 50, buttons = 5;
var currentPage = lowerLimit = upperLimit = Math.min(9, totalPages);
//Search boundaries
for (var b = 1; b < buttons && b < totalPages;) {
if (lowerLimit > 1 ) { lowerLimit--; b++; }
if (b < buttons && upperLimit < totalPages) { upperLimit++; b++; }
}
//Do output to a html element
for (var i = lowerLimit; i <= upperLimit; i++) {
if (i == currentPage) $('#pager').append('<li>' + i + '</li> ');
else $('#pager').append('<li><em>' + i + '</em></li> ');
}
List<int> pages = new List<int>();
int pn = 2; //example of actual pagenumber
int total = 8;
for(int i = pn - 9; i <= pn + 9; i++)
{
if(i < 1) continue;
if(i > total) break;
pages.Add(i);
}
return pages;
I made a pagination class and put in on Google Code a while ago. Check it out its pretty simple
http://code.google.com/p/spaceshipcollaborative/wiki/PHPagination
$paging = new Pagination();
$paging->set('urlscheme','class.pagination.php?page=%page%');
$paging->set('perpage',10);
$paging->set('page',15);
$paging->set('total',3000);
$paging->set('nexttext','Next Page');
$paging->set('prevtext','Previous Page');
$paging->set('focusedclass','selected');
$paging->set('delimiter','');
$paging->set('numlinks',9);
$paging->display();
I would use something simple on the page you are showing the paginator, like:
if (
$page_number == 1 || $page_number == $last_page ||
$page_number == $actual_page ||
$page_number == $actual_page+1 || $page_number == $actual_page+2 ||
$page_number == $actual_page-1 || $page_number == $actual_page-2
) echo $page_number;
You can adapt it to show each 10 or so pages with % operator ...
I think using switch() case would be better in this case, I just don't remember the syntax now
Keep it Simple :)
If it's possible to generate the pagination on the client, I would suggest my new Pagination plugin: http://www.xarg.org/2011/09/jquery-pagination-revised/
The solution to your question would be:
$("#pagination").paging(1000, { // Your number of elements
format: '. - nncnn - ', // Format to get Pages: ... 3 4 [5] 6 7 ...
onSelect: function (page) {
// add code which gets executed when user selects a page
},
onFormat: function (type) {
switch (type) {
case 'block': // n and c
return '<a>' + this.value + '</a>';
case 'fill': // -
return '...';
case 'leap': // .
return 'Pages:';
}
}
});
The code of the CodeIgniter pagination-class can be found on GitHub
(what you call) Smart pagination can be achieved by configuration.
$config['num_links'] = 2;
The number of "digit" links you would like before and after the
selected page number. For example, the number 2 will place two digits
on either side, as in the example links at the very top of this page.
Related
I tried to make a PHP pagination like this:
$count = $this->dataBaseFunctions->countItems();
$resultperPage = 10;
$offset = 0;
$adjacents = 3;
$totalPages = ceil(intval($count) / $resultperPage);
if (isset($_GET['offset'])) {
$offset = trim($_GET['offset']);
}
$j = $adjacents;
while ($j > 0) {
if (($offset / 10) - 1 > 0) {
echo '' . ($offset - 10 - ($j * 10)) . ' ';
}
$j--;
}
/*for ($j = $adjacents; $j > 0; $j--) {
echo '' . ($offset - 10 - ($j * 10)) . ' ';
}*/
echo '[' . ($offset - 10) . '] ';
for ($j = 1; $j < ($adjacents + 1); $j++) {
echo '' . ($offset - 10 + ($j * 10)) . ' ';
}
The result should look like this (Brackets = current clicket page):
[0] 1 2 3
When I click "3" it should look like this (works so far):
0 1 2 [3] 4 5 6
But when I click "1" the result looks like this:
-2 -1 0 [1] 2 3 4
The "0" is not a problem, I just 'echoed' it for debugging.
I know that I dont set the right conditions for not showing pages below 1 but I dont get it how to make it right. Seems like I have tomatoes on my eyes... The echo is just for testing - later I save the whole pagination links into a variable to assign it to the bottom of the page. Its a bit of debugging code you see here but it shows what I try to do. Please let me know if I can improve the question or if there are missing informations like: "why you do ($offset / 10) -1 > 0" ;-)
Later I need to do same stuff in JS but I think I can manage that, when I know what I did wrong in the PHP version.
*Maybe it's a bad Idea what I try to do there?
This one should do the trick:
Now including the $adjacents
$count = $this->dataBaseFunctions->countItems();
$resultperPage = 10;
$offset = 0;
$adjacents = 3;
$totalPages = ceil(intval($count) / $resultperPage);
if (isset($_GET['offset'])) {
$offset = trim($_GET['offset']);
}
$start = ($offset-$adjacents) > 0 ? ($offset-$adjacents) : 0;
$end = ($offset+$adjacents) < $totalPages ? ($offset+$adjacents) : $totalPages;
$pager = "";
for ($i = 0; $i < $totalPages; $i++) {
if ($i >= $start && $i <= $end) {
$pager .= $offset != $i ? '' . $i . ' ' : "[$i] ";
}
}
echo $pager;
Currently I have a functioning pagination script, although I'm missing on feature. At the moment it's possible for hundreds of pages to be showing in the $pages list, because there's no filter on to show between, for example, [1] [...] 5, 6, 7 [..] [45]. Here's my code:
/** Pagination **/
$limit = 7;
$query = "SELECT COUNT(*) FROM users";
$result = $db->prepare($query);
$result->execute();
$pages_query = $result->fetchColumn(0);
$count = number_format($pages_query);
$pages = ceil($pages_query / $limit);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $limit;
ob_start();
echo("<span class='alignright'>");
if ($pages >= 1 && $page <= $pages){
if($page > 1){
$next = ($page - 1);
$link = "?page=$next";
echo("<a class='paginate' href='$link'><i class='icon-caret-left'></i></a>");
}
for ($x=1; $x<=$pages; $x++){
echo ($x == $page) ? "<strong style='font-weight: bold!important;'><a class='paginate' href='?page=$x'>$x</a></strong>" : "<a class='paginate' href='?page=$x'>$x</a>";
}
if($page < $pages){
$next = ($page + 1);
$link = "?page=$next";
echo("<a class='paginate' href='$link'><i class='icon-caret-right'></i></a>");
}
echo("</span>");
if($count > 0){
echo("<span class='smalltext'>Page <strong class='half'>$page</strong> of $pages:</span>");
} else {
echo("<span class='smalltext'>There are <span class='half'>$count</span> results to display.</span>");
}
$pagintion = ob_get_clean();
(It's been stripped from other junk that was in it but that's the general frame.) Basically I'm trying to figure out how to limit it to have "between pages" down the bottom as specified in the top part of the question. Something like:
[<] [1] ... [4] [5] [6] ... [45] [>]
If that makes sense.
you can try LIMIT with in your query itself
SELECT * FROM TABLE_NAME LIMIT STARTING_RESULT_NUMBER, RESULTS_PER_PAGE
RESULTS_PER_PAGE is no.of items per page you want to display
STARTING_RESULT_NUMBER =(CURRENT_PAGE_NUMBER*RESULTS_PER_PAGE)
In order to change the list of pages to something like [<] [1] ... [4] [5] [6] ... [45] [>] rather than showing all pages numbers, you can replace your for loop by something like :
echo "<a class='paginate' href='?page=1'>1</a>";
if($page > 3) {echo "...";}
if($page > 2) {echo "<a class='paginate' href='?page=" . $x-1 . "'>" . $x-1 "</a>";}
if($page != 1 && $page != pages) {echo "<a class='paginate' href='?page=" . $x . "'>" . $x "</a>";}
if($page < $pages-1) {echo "<a class='paginate' href='?page=" . $x+1 . "'>" . $x+1 "</a>";}
if($page < $pages-2) {echo "...";}
if($pages >1) {echo "<a class='paginate' href='?page=1'>1</a>";}
Il will show the first page, the last pages, the current pages and the ones just before and just after.
My personal meaning with pagination is that it must be readable and simple to change later on.
I typed the following code based on you're example:
$totalPages = 145; //the total amount of pages
$selectedPage = 40; //the selected page
$pages = array(); //the array which is gonna hold the pages we need to display
$offset = 3; //the number of pages to select around the selected page
$closePages = range($selectedPage - $offset, $selectedPage + $offset); //select the pages that are in $offset of the selected page
array_filter($closePages, function($x) { //filter the pages below 1 and above $totalPages
return ($x <= $totalPages && $x >= 1 ? true : false );
});
array_push($pages, 1); //add the first page
array_push($pages, '...'); //add some dots
$pages = array_merge($pages, $closePages);
array_push($pages, '...'); //and again add some dots
array_push($pages, $totalPages); //add the last page
Then you use a foreach loop to display the pages:
foreach($pages as $page) {
if (is_numeric($page)) {
if ($page != $selectedPage) $content .= ' ' . $page . ' ';
else $content .= ' <strong>' . $page . '</strong> ';
} else
$content .= '[...]';
}
Some explanation after you're comment on this answer:
The $totalPages variable must be the total amount of pages on the page (from you're example) and the $selectedPage is the page that is selected at this moment.
$totalPages = ceil($pages_query / $limit);
$selectedPage = isset($_GET['page']) ? $_GET['page'] : 1;
I have many table rows on my database which contain at least 100 or more of them. Therefore, I need to limit the pagination numbers that is displayed on my page.
Somethime like this:
Prev 1 2 3 4 5 6 .. 40 41 Next
Should become this:
Prev 1 2 .. 6 7 8 9 10 .. 40 41 Next
The code below is what I use to create a basic pagination:
<?php
require 'php/connect.inc.php';
$per_page = 6;
$pages_query = mysql_query("SELECT COUNT('user_id') FROM users");
$pages = ceil(mysql_result($pages_query, 0) / $per_page);
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_page;
$query = mysql_query("SELECT `user_username` FROM `users` LIMIT $start, $per_page");
while($mysql_fetch_assoc = mysql_fetch_assoc($query)){
echo '<p>', $mysql_fetch_assoc['user_username'] ,'</p>';
}
if ($pages >= 1 && $page <= $pages){
for ($x=1; $x <= $pages; $x++){
echo ($x == $page) ? '<strong>'.$x.'</strong> ' : ''.$x.'';
}
}
?>
It was not easy to get the question but comparing the code and what you want ( Prev 1 2 3 ... 41 42 43 Next ) and readng the comments I hope I can help you.
If I get it right you try to create a navigation like here http://goo.gl/UzD02 (bottom of the site). Your algorithm do it for all of the found pages:
if ($pages >= 1 && $page <= $pages){
for ($x=1; $x <= $pages; $x++){
echo ($x == $page) ? '<strong>'.$x.'</strong> ' : ''.$x.'';
}
}
if $pages = 20 and $page < page you will always get:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
A possible solution would be this
$dots = true;
if ($pages >= 1 && $page <= $pages){
for ($x=1; $x <= $pages; $x++){
if ($x > $page + 1) {
$dots = true;
}
if($x > 5 && $dots) {
echo "...";
$dots = false;
if ($x < $page - 1) {$x = $page - 1;}
elseif ($x < $pages - 3) {$x = $pages - 3;}
} else {
echo ($x == $page) ? '<strong>'.$x.'</strong> ' : ''.$x.'';
}
}
}
I have not tested this code but this the part of the code, where you have to look at and imo it should work. The code also could be better.
EDIT after comment
For the pagination like google just do it like this:
$numberOfPages = 10;
if($pages >= 1 && $page <= $pages){
if($pages + $numberOfPages < $pages) {
$numOfSlectablePages = $pages + $numberOfPages;
} else {
$numOfSlectablePages = $pages;
}
for ($x = $page; $x <= $numOfSlectablePages; $x++){
echo ($x == $page) ? '<strong>'.$x.'</strong> ' : ''.$x.'';
}
}
it's not exactly like google, but I am realy busy right now and i think you get the right direction. If you want it like google just think a little bit about what you have to do or let me know, that you have no idea and I will give an answer on Sunday evening.
I have a pagination system, that fetches all of the results from a database & then loads them into a pagination.
Let's say I set the limit to 5 results per page, it will generate more pages, and order the results by date & time.
But I have a problem, my system always missing the most new result (by date/time) in the database, I have no idea why..
This is the code:
// how many rows to show per page
$rowsPerPage = 10;
// by default we show first page
$page_num = 1;
// if $_GET['page'] defined, use it as page number, $_GET gets the page number out of the url
//set by the $page_pagination below
if(isset($_GET['page'])){$page_num = $_GET['page'];}
//the point to start for the limit query
$offset = $page_num;
// Zero is an incorrect page, so switch the zero with 1, mainly because it will cause an error with the SQL
if($page_num == 0) {$page_num = 1;}
// counting the offset
$sql = "SELECT * FROM comments ORDER BY date, time desc LIMIT $offset, $rowsPerPage";
$res = $pdo->query($sql);
// how many rows we have in database
$sql2 = "SELECT COUNT(comment_id) AS numrows FROM comments";
$res2 = $pdo->query($sql2);
$row2 = $res2->fetch();
$numrows = $row2['numrows'];
// print the random numbers
while($row = $res->fetch())
{
//Echo out your table contents here.
echo $row[1].'<BR>';
echo $row[2].'<BR>';
echo '<BR>';
}
// how many pages we have when using paging?
$numofpages = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = "events.php?";
$page_pagination = '';
if ($numofpages > '1' ) {
$range = 10; //set this to what ever range you want to show in the pagination link
$range_min = ($range % 2 == 0) ? ($range / 2) - 1 : ($range - 1) / 2;
$range_max = ($range % 2 == 0) ? $range_min + 1 : $range_min;
$page_min = $page_num- $range_min;
$page_max = $page_num+ $range_max;
$page_min = ($page_min < 1) ? 1 : $page_min;
$page_max = ($page_max < ($page_min + $range - 1)) ? $page_min + $range - 1 : $page_max;
if ($page_max > $numofpages) {
$page_min = ($page_min > 1) ? $numofpages - $range + 1 : 1;
$page_max = $numofpages;
}
$page_min = ($page_min < 1) ? 1 : $page_min;
if ( ($page_num > ($range - $range_min)) && ($numofpages > $range) ) {
$page_pagination .= '<a class="num" title="First" href="'.$self.'page=1"><</a> ';
}
if ($page_num != 1) {
$page_pagination .= '<a class="num" href="'.$self.'page='.($page_num-1). '">Previous</a> ';
}
for ($i = $page_min;$i <= $page_max;$i++) {
if ($i == $page_num)
$page_pagination .= '<span class="num"><strong>' . $i . '</strong></span> ';
else
$page_pagination.= '<a class="num" href="'.$self.'page='.$i. '">'.$i.'</a> ';
}
if ($page_num < $numofpages) {
$page_pagination.= ' <a class="num" href="'.$self.'page='.($page_num + 1) . '">Next</a>';
}
if (($page_num< ($numofpages - $range_max)) && ($numofpages > $range)) {
$page_pagination .= ' <a class="num" title="Last" href="'.$self.'page='.$numofpages. '">></a> ';
}
}
echo $page_pagination.'<BR><BR>';
echo 'Number of results - '.$numrows ;
echo ' and Number of pages - '.$numofpages.'<BR><BR>';
$res2->closeCursor();
Question:
What have I done wrong? I cant' really see anything wrong, but I always get this error:
Notice: Undefined variable: page_pagination
Line:
echo $page_pagination.'<BR><BR>';
It always happens on a different line, depends on the results amount, but to fix that I need to declare page_pagination = ''; before the whole thing.
How can I fix this and what is causing this problem?
Thanks.
Your $offset is being set to 1. The newest one is always missing because it's going form 1-10 rather than 0-9. Index starts at 0. The following should work.
$offset = ($rowsPerPage * $page_num) - $rowsPerPage;
I know this is a common problem as I have searched for answers before deciding to post, but I can't seem to figure out a solution.
PROBLEM: I have a pagination script (PHP) to use for my search results. As is apparently common, the first page results show fine, then fail when moving onto page 2, 3 etc.
I get an 'unknown index' error for each of my variables used in the search when clicking through to page 2, 3 etc.
So I $_GET these variables from my form:
$_SESSION['var1']= $_GET['var1'];
$_SESSION['var2']= $_GET['var2'];
$_SESSION['var3']= $_GET['var3'];
Points to note:
A Session has already been started in my header; I'm using $_GET because i prefer not having the 'resubmit' warning if a user goes 'back'; variables are all cleaned (just not shown in code as its long enough already); I have to use the $_GET variables with the WHILE loop as they calculate distance, age etc of each result.
My pagination script:
$limit = 4;
$query = "SELECT COUNT(*) as num FROM $tableName";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
$stages = 3;
$page = mysql_escape_string(isset($_GET['page'])) ? (int)$_GET['page'] : 1;
if($page) {
$start = ($page - 1) * $limit;
} else {
$start = 0;
}
// Get page data
$query1 = "SELECT * FROM $tableName ORDER BY joindate DESC LIMIT $start, $limit";
$result = mysql_query($query1);
// Initial page num setup
if ($page == 0){$page = 1;}
$prev = $page - 1;
$next = $page + 1;
$lastpage = ceil($total_pages/$limit);
$LastPagem1 = $lastpage - 1;
$paginate = '';
if($lastpage > 1) {
$paginate .= "<div class = 'hp1col'><div class='paginate'>";
$pagetotal = $total_pages.' Results';
// Previous
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>Previous</a>";
} else {
$paginate.= "<span class='disabled'>previous</span>";}
// Pages
if ($lastpage < 7 + ($stages * 2)) // Not enough pages to breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page){
$paginate.= "<span class='current'>$counter</span>";
}else{ $paginate.= "<a href='$targetpage?page=$counter'>$counter</a>";}
}
}
// Next
if ($page < $counter - 1){
$paginate.= "<a href='$targetpage?page=$next'>Next</a>";
} else {
$paginate.= "<span class='disabled'>Next</span>";
}
$paginate.= "</div></div>";
}
while($row = mysql_fetch_array($result))
{
if (($part1 >= $_SESSION['var1']) AND ($part2 <= $_SESSION['var2']) AND ($part3 <= $_SESSION['var3'])) {
echo
"[Results]
}
}
echo $paginate;
I tried starting a new session in this if statement but it didn't help:
if ($page > 1){
$paginate.= "<a href='$targetpage?page=$prev'>Previous</a>";
} else {
$paginate.= "<span class='disabled'>previous</span>";}
I hope someone can help. I apologise for the slab of code in the question, but I thought it best just to put everything in for ease in, hopefully, someone being able to help.
Thanks
So you need to pass those query parameters through to the next page. If your page expects $_GET['var1'] to be present but you don't have ?var1=foo in the URL, it obviously won't work. The easiest way to handle this is http_build_query:
printf('Next',
$targetpage,
http_build_query(array('page' => 2) + $_GET));
This preserves all current values in $_GET and adds a page=2 parameter to it. Modify as needed for your case.