nita Posted May 5, 2007 Share Posted May 5, 2007 Hi. I have a problem with pagination of my mysql database results. Script is printing the first 10 results and links to the rest with no problem. But once i press on the link is putting me back to root of application, instead of paging out the rest of results. to test it go to : www.nita-on-line.com/movies/ if(isset($_GET['cat'])) // when looking at selected category of movies { // printing out menu with categories $result = mysql_query("SELECT * FROM category ORDER BY cat") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { echo "<A href='index.php?cat=$row[cat]'>$row[cat]</a><br>"; } $rowsPerPage = 10; $pageNum = 1; if(isset($_GET['page'])) { $pageNum = $_GET['page']; } $offset = ($pageNum - 1) * $rowsPerPage; $cat=$_GET['cat']; $result=mysql_query("SELECT * FROM movies WHERE cat='$cat' ORDER BY name LIMIT $offset, $rowsPerPage") or die(mysql_error()); while($row=mysql_fetch_array($result)) { include "display_rec.php"; } $query = "SELECT COUNT(name) AS numrows FROM movies WHERE cat='$cat'"; $result = mysql_query($query) or die('Error, query failed'); $row1 = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row1['numrows']; $maxPage = ceil($numrows/$rowsPerPage); $self = $_SERVER['PHP_SELF']; if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ''; $first = ''; } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self.php?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ''; $last = ''; } echo $first . $prev . " Page $pageNum of $maxPage " . $next . $last; } if someone can help me to find a bug in this script, please Thanks a lot in advance. Nita Link to comment https://forums.phpfreaks.com/topic/50106-solved-php-pagination-problem/ Share on other sites More sharing options...
nita Posted May 5, 2007 Author Share Posted May 5, 2007 i did fix it now ! if ($pageNum > 1) { $cat = $_GET['cat']; $page = $pageNum - 1; $prev = " <a href=\"$self?cat=$cat&page=$page\">[Prev]</a> "; $first = " <a href=\"$self?cat=$cat&page=1\">[First Page]</a> "; } else { $prev = ''; $first = ''; } if ($pageNum < $maxPage) { $cat = $_GET['cat']; $page = $pageNum + 1; $next = " <a href=\"$self?cat=$cat&page=$page\">[Next]</a> "; $last = " <a href=\"$self?cat=$cat&page=$maxPage\">[Last Page]</a> "; } else { $next = ''; $last = ''; } echo $first . $prev . " Page $pageNum of $maxPage " . $next . $last; Link to comment https://forums.phpfreaks.com/topic/50106-solved-php-pagination-problem/#findComment-246057 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.