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