Jump to content

[SOLVED] Yes, another PAGINATION problem...


suttercain

Recommended Posts

Hi guys,

 

I have been playing with this code for a little while and can't seem to get it working right:

 

<?php
if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
}

$query = mysql_query("SELECT count(*) FROM comics WHERE title = '".mysql_real_escape_string($search)."' AND type ='Comic Book'    
ORDER BY title, issue_number") or die (mysql_error());
//PAGENATION
$query_data = mysql_fetch_row($query);
$numrows = $query_data[0];
$rows_per_page = 25;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
   $pageno = 1;
} elseif ($pageno > $lastpage) {
   $pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = mysql_query("SELECT * FROM comics WHERE title = '".mysql_real_escape_string($search)."' AND type ='Comic Book'    
ORDER BY title, issue_number $limit");

//SEARCH RESULTS DISPLAYED HERE

if ($pageno == 1) {
   echo " FIRST PREV ";
} else {
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
   $prevpage = $pageno-1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
}
echo " ( Page $pageno of $lastpage ) ";

if ($pageno == $lastpage) {
   echo " NEXT LAST ";
} else {
   $nextpage = $pageno+1;
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
   echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
}
}
?>

 

The search result shows the first page and the first 25 results. It even displays the number of pages found and also the pagination links at the bottom. The problem is when you click 'NEXT' or 'LAST' it takes you to page2 and nothing is displayed.

 

Example:

http://www.supermandatabase.com/comics/comicSearch.php?title=supergirl

 

Any suggestions?

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/70389-solved-yes-another-pagination-problem/
Share on other sites

Okay... a new question ... I know I can increment and display the number of results for 1 - 25... how would I get it to say 26-50 on page two and so on?

 

If I do this:

 

$i=1;

 

while {

echo $i;

$i++;

}

 

I get:

1.

2.

3.

4.

etc on every page...

 

Thanks

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.