dunc@sf Posted October 15, 2007 Share Posted October 15, 2007 Morning, ladies and gents. First post here - got a bit of a problem with my website. I'm using a pagination function on my website to give page numbers for search results (it's a fishkeeping website with numerous profiles so a bit of a necessity). The basics are that $act, $page and $limit variables are sent through URLs and any additional search preferences (region, category or whatever) are stored in session variables if it's a fresh search (if $f==fresh, <input type=hidden name=f> on the search form), or retrieved from session variables if it isn't. When the results are displayed, as expected the results link to either a separate fish profile page or in the case of our community database it'll link to community.php?id=int and display the individual details of a club or affiliate. My problem is that after viewing a club or fish profile, if the user hits back, I get the classic "page cannot be displayed". Most of the code is here: if ($num_rows > 0) { echo '<table class="kbTable" align="left" width="604"> <p><h2>'.$title.'s</h2></p>'; //-----> Start page maths $pages = intval($num_rows/$limit); // Number of results pages. // $pages now contains int of pages, unless there is a remainder from division. if ($num_rows % $limit) $pages++;// has remainder so add one page $current = ($page/$limit) + 1; // Current page number. if (($pages < 1) || ($pages == 0)) $total = 1;// If $pages is less than one or equal to 0, total pages is 1. else $total = $pages;// Else total pages is $pages value. $first = $page + 1; // The first result. if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) $last = $page + $limit;//If not last results page, last result equals $page plus $limit. else $last = $num_rows;// If last results page, last result equals total number of results. //-----> Finish page maths echo '<tr> <td align="left" class="bluTxt10px" colspan="2"> Page <b>'.$current.'</b> of <b>'.$total.'</b>. Results <b>'.$first.'</b> - <b>'.$last.'</b> of <b>'.$num_rows.'</b> </td> <td align="right" class="bluTxt10px">Results per page: '; if ($limit == 6) { echo '6 |'; } else { echo '<a href="'.$PHP_SELF.'?act=$act&page='.$page.'&limit=6" class="bluTxt10px">6</a> |'; } if ($limit == 15) { echo ' 15 |'; } else { echo ' <a href="'.$PHP_SELF.'?act=$act&page='.$page.'&limit=15" class="bluTxt10px">15</a> |'; } if ($limit == 30) { echo ' 30 |'; } else { echo ' <a href="'.$PHP_SELF.'?act=$act&page='.$page.'&limit=30" class="bluTxt10px">30</a> |'; } if ($limit == 60) { echo ' 60'; } else { echo ' <a href="'.$PHP_SELF.'?act=$act&page='.$page.'&limit=60" class="bluTxt10px">60</a>'; } echo '</td> </tr>'; $sql .= " ORDER BY name ASC LIMIT $page, $limit"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)) { $items[] = array(1 => $row['name'], 2 => $row['owner'], 3 => $row['id']); } // Default # of Columns $numcols = 3; // Number of Items $numitems = count($items); // Number of Rows $numrows = ceil($numitems/$numcols); for ($row=1; $row <= $numrows; $row++) { $cell = 0; echo ' <tr>'."\n"; for ($col=1; $col <= $numcols; $col++) { echo ' <td width="'.round(100/$numcols).'%" class="resTD">'."\n"; if ($col===1) { $cell += $row; print '<span class="clubName"> <a href="community.php?id='.$items[$cell - 1][3].'">'.$items[$cell - 1][1].'</a> </span> <br />'; print $items[$cell - 1][2]; } else { $cell += $numrows; print '<span class="clubName"> <a href="community.php?id='.$items[$cell - 1][3].'">'.$items[$cell - 1][1].'</a> </span> <br />'; print $items[$cell - 1][2]; } echo ' </td>'."\n"; } echo ' </tr>'."\n"; } //-----> Next page processing if ($num_rows > $limit) { echo '<tr><td colspan="3" align="center" class="bluTxt10px">'; if ($page != 0) { // Don't show back link if current page is first page. $back_page = $page - $limit; echo("<a href=\"$PHP_SELF?act=$act&page=$back_page&limit=$limit\" class=\"bluTxt10px\"><< </a>\n"); } if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // If last page, don't give next link. $next_page = $page + $limit; echo("<a href=\"$PHP_SELF?act=$act&page=$next_page&limit=$limit\" class=\"bluTxt10px\"> >></a>\n"); } echo '<br>'; for ($i=1; $i <= $pages; $i++) // loop through each page and give link to it. { $ppage = $limit*($i - 1); if ($ppage == $page){ echo("<b>$i</b> \n");} // If current page don't give link, just text. else{ echo("<a href=\"$PHP_SELF?act=$act&page=$ppage&limit=$limit\" class=\"bluTxt10px\">$i</a> \n");} } echo '</td></tr>'; Any ideas? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/73286-pagination-back-button-problems/ Share on other sites More sharing options...
dunc@sf Posted October 15, 2007 Author Share Posted October 15, 2007 How did this get on the second page already?! Shameless bump! Quote Link to comment https://forums.phpfreaks.com/topic/73286-pagination-back-button-problems/#findComment-369905 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.