CodeMama Posted August 7, 2009 Share Posted August 7, 2009 I have an alphabetical menu list for browsing so say a user chooses "G" then picks a "G" record to view, whats the easiest way to make a "back to results" link and take them back to the letter they chose? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/169230-solved-easiest-way-to-return-to-previous-search-results/ Share on other sites More sharing options...
darkfreaks Posted August 7, 2009 Share Posted August 7, 2009 have you read phpfreaks basic pagination tutorial Basic Pagination Quote Link to comment https://forums.phpfreaks.com/topic/169230-solved-easiest-way-to-return-to-previous-search-results/#findComment-892952 Share on other sites More sharing options...
CodeMama Posted August 7, 2009 Author Share Posted August 7, 2009 yes but that is numerical pagination these are passing variables in the url like letter=G to a completely other page so I have to jump back over a page back to letter=G or whatever I tried using the $selectedLetter which is what the script uses but it didn't pick it up it just said letter=$selectedLetter Quote Link to comment https://forums.phpfreaks.com/topic/169230-solved-easiest-way-to-return-to-previous-search-results/#findComment-892987 Share on other sites More sharing options...
CodeMama Posted August 7, 2009 Author Share Posted August 7, 2009 this is my alpha links pagination code...is it even called pagination? <?php // Function to create paging. function createPaging($selectedLetter = null) { $letters = range('A','Z'); array_push($letters, 'nums'); $menu = ''; foreach($letters as $letter) { if($letter == $selectedLetter && $selectedLetter != 'nums') { $menu .= sprintf('%s ', $letter); } else if($letter == $selectedLetter && $selectedLetter == 'nums') { $menu .= sprintf('%s ', '#', '<hr>'); } else { if($letter == 'nums') { $menu .= sprintf('<a href="browse.php?letter=%s">%s</a> ', 'nums', '#'); } else { $menu .= sprintf('<a href="browse.php?letter=%s">%s</a> ', $letter, $letter); } } } return $menu; echo ('<HR>'); } // Function to show just paging. function index() { // Echo only paging. echo createPaging(); } // Function to show results if page was given. function browse($selectedLetter) { // Echo paging. echo createPaging($selectedLetter); echo '<br><hr>'; //Show all restaurants that start with $letter not between "A" and "Z" if ($selectedLetter == "nums") { for($i = 0; $i <= 9; $i++) { $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE name LIKE '$i%'"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { echo '<br>'; $name = $row['name']; printf('<br><a href="view.php?ID=%s"><b>%s</b><br />%s<br /><br /></a>', $row['ID'], $row['name'], $row['address']); } } } else { $sql = "SELECT DISTINCT ID, name, address FROM restaurants WHERE name LIKE '$selectedLetter%'"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { $name = $row['name']; printf('<a href="view.php?ID=%s"><b>%s</b><br />%s<br /><br /></a>', $row['ID'], $row['name'], $row['address']); } } } // Main controller which page to show. if (isset($_GET['letter'])) { browse($_GET['letter']); } elseif (basename($_SERVER['SCRIPT_FILENAME']) == "browse.php" ) { browse('A'); } else { index(); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169230-solved-easiest-way-to-return-to-previous-search-results/#findComment-892988 Share on other sites More sharing options...
darkfreaks Posted August 7, 2009 Share Posted August 7, 2009 what about something like this: <?php // Build Previous Link if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">«</a> "; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i &letter=$letter\">$i</a> "; } } // Build Next Link if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">»</a>"; } echo "</p>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169230-solved-easiest-way-to-return-to-previous-search-results/#findComment-892997 Share on other sites More sharing options...
CodeMama Posted August 7, 2009 Author Share Posted August 7, 2009 easiest was to just use the javascript function <a href="javascript:history.back()">Back to Previous</a> Quote Link to comment https://forums.phpfreaks.com/topic/169230-solved-easiest-way-to-return-to-previous-search-results/#findComment-893010 Share on other sites More sharing options...
darkfreaks Posted August 7, 2009 Share Posted August 7, 2009 nevermind Quote Link to comment https://forums.phpfreaks.com/topic/169230-solved-easiest-way-to-return-to-previous-search-results/#findComment-893012 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.