suttercain Posted September 23, 2007 Share Posted September 23, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/70389-solved-yes-another-pagination-problem/ Share on other sites More sharing options...
suttercain Posted September 23, 2007 Author Share Posted September 23, 2007 I had to add the search phrase into the pagination links via the get method. SC Quote Link to comment https://forums.phpfreaks.com/topic/70389-solved-yes-another-pagination-problem/#findComment-353612 Share on other sites More sharing options...
suttercain Posted September 23, 2007 Author Share Posted September 23, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/70389-solved-yes-another-pagination-problem/#findComment-353633 Share on other sites More sharing options...
suttercain Posted September 23, 2007 Author Share Posted September 23, 2007 Got it... I took the page number multiplied it by 25 then subtracted it by 24 to give me the starting point for $i. Quote Link to comment https://forums.phpfreaks.com/topic/70389-solved-yes-another-pagination-problem/#findComment-353639 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.