Jump to content

[SOLVED] Easiest way to return to previous search results?


CodeMama

Recommended Posts

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

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&nbsp', $letter);
      }
      else if($letter == $selectedLetter && $selectedLetter == 'nums')
      {
         $menu .= sprintf('%s&nbsp', '#', '<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();
   
}
    
?>

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>"; 
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.