Jump to content

Pagination results


graham23s

Recommended Posts

Hi Guys,

 

i'm having a problem with my pagination links, i can limit the query ok,but i'm only seeing 1 link:

 

[1]

 

but i should see 2

 

[1][2]

 

<?php
  ## Pagination
  if(!isset($_GET['page'])){ 
    $page = 1; 
  } else { 
    $page = $_GET['page']; 
  } 
  
  ## results
  $perpage = 1;
  
  ## start index
  $from = (($page * $perpage) - $perpage);
        
  //======================== COMPILE QUERY ========================//
  $searchquery  = "SELECT * FROM `users` WHERE 1=1 ";
  
  ## GENDER #########################################################
  if(isset($gender) && ($gender != '0')) { 
  
  $searchquery .= "AND `gender`='$gender' "; 
  $addressbar .= "&gender=$gender";
  
  }
  ## HERE FOR #######################################################
  if(isset($herefor) && ($herefor != '0')) { 
  
  $searchquery .= "AND `herefor`='$herefor' "; 
  $addressbar .= "&herefor=$herefor";
  
  }  
  ## COUNTRY ########################################################
  if(isset($country) && ($country != '0')) { 
  
  $searchquery .= "AND `country`='$country' "; 
  $addressbar .= "&country=$country";
  
  }  
  ## ETHNICITY ######################################################
  if(isset($ethnicity) && ($ethnicity != '0')) { 
  
  $searchquery .= "AND `ethnic`='$ethnicity' "; 
  $addressbar .= "&ethnicity=$ethnicity";
  
  } 
  ## HAIR ###########################################################
  if(isset($hair) && ($hair != '0')) { 
  
  $searchquery .= "AND `hair`='$hair' "; 
  $addressbar .= "&hair=$hair";
  
  }  
  ## BUILD ##########################################################
  if(isset($build) && ($build != '0')) { 
  
  $searchquery .= "AND `build`='$build' "; 
  $addressbar .= "&build=$build";
  
  }    
  ## EYE_C ##########################################################
  if(isset($eyes) && ($eyes != '0')) { 
  
  $searchquery .= "AND `eye_c`='$eyes' "; 
  $addressbar .= "&eyes=$eyes";
  
  }     
  ## AGES ###########################################################
  $searchquery .= "AND `year` BETWEEN YEAR(CURDATE() - INTERVAL $toage YEAR) AND YEAR(CURDATE() - INTERVAL $fromage YEAR) LIMIT $from, $perpage";
  //======================== COMPILE QUERY ========================//
  
  ## run query
  $resultquery = mysql_query($searchquery);
  
  ## num results
  $numresults = mysql_num_rows($resultquery);
  
  ## no results
  if($numresults == 0) {

  echo ('<br /><span class="gallery_header">Sorry, no results were found!</span><br />');
  include("includes/footer.php");
  exit;
    
  } else {
   
  echo ('<br /><span class="gallery_header">We have found you <b>'.$numresults.'</b> matches!</span><br /><br />');
  
  while($row = mysql_fetch_array($resultquery)) {
  
  ## details
  $searchid = $row['id'];
  $searchusername = $row['username'];
  $searchthumb = $row['thumbnail'];
  
  $nopic = (!empty($searchthumb)) ? "<img src=\"thumbs/$searchthumb\">" : "<img src=\"images/noimgup.jpg\"";
   
  ## some results
  echo ("<table class=\"sub_table\" align=\"center\" width=\"300\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">");
  echo ("<tr>");
  echo ("<td class=\"sub_table\" align=\"center\">$nopic</td>");
  echo ("</tr>");
  echo ("</table>");
  echo ("<br />");  
  
  } // end while
  
  ## Pagination Links
  echo ("<div id=\"pagination\" align=\"left\">");
  echo ("<hr /><br />");
  
        // Figure out the total number of pages. Always round up using ceil() 
        $totalpages = ceil($numresults / $perpage); 
        
        // Build Previous Link 
        if($page > 1){ 
            $prev = ($page - 1); 
            echo " <a href=\"".$_SERVER['PHP_SELF']."?page=$prev$addressbar\">PREV </a> "; 
        } 
        
        for($i = 1; $i <= $totalpages; $i++){ 
            if(($page) == $i){ 
                echo "[<b>$i</b>] "; 
                } else { 
                    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i$addressbar\">$i</a> "; 
            } 
        } 
        
        // Build Next Link 
        if($page < $totalpages){ 
            $next = ($page + 1); 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next$addressbar\">NEXT</a>"; 
        } 
        
  echo ("</div>");    
  
  }
  
  } // end if
?>

 

any help on this would be great

 

thanks

 

Graham

Link to comment
Share on other sites

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.