deansaddigh Posted June 15, 2010 Share Posted June 15, 2010 I have code for my pagination but its working incorerectly as you can see from this page http://www.languageschoolsuk.com/view_all_schools.php Some pages are empty when using the pagination. heres the code //pagination $rowsPerPage = 5; $pageNum = 1; if(isset($_GET['page'])) { $pageNum = $_GET['page']; $pageNum = trim($pageNum); } $offset = ($pageNum - 1) * $rowsPerPage; // select school details based on school id $query = "SELECT image_school.image_id, image_school.school_id, school.name AS school_name,school.school_id, school.street, school.town, school.city, school.county, school.region, school.school_facts, school.general_info, school.school_facilities, image.image_id, image.path, image.name AS image_name FROM image_school JOIN school ON image_school.school_id = school.school_id RIGHT JOIN image ON image_school.image_id = image.image_id ORDER BY school_name LIMIT $offset, $rowsPerPage"; $result = mysql_query($query, $conn) or die('Error, query failed'); /***********************************/ //******Joes Pagination continued // how many rows we have in database $query = "SELECT COUNT(*) AS numrows FROM studentphotos"; $result = mysql_query($query) or die('Error, Count query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page 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 = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">Next »</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } echo '<br/>'; echo '<br/>'; //If there is only one page then do nothing. if ($maxPage ==1) { } //Else show user page information and links to browse multiple pages. else { // print the navigation link echo '<p class ="pagination">'; echo $first . $prev . $nav . $next . $last; echo '</p>'; } Any help would be brilliant, thanks in advance Link to comment https://forums.phpfreaks.com/topic/204845-can-some-help-with-my-pagination/ Share on other sites More sharing options...
deansaddigh Posted June 15, 2010 Author Share Posted June 15, 2010 oopsy, it should be schools, not student photos for a start on the sql count. Seems to work now. Is the way i have done the pagination ok? Link to comment https://forums.phpfreaks.com/topic/204845-can-some-help-with-my-pagination/#findComment-1072371 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.