Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.