Jump to content

pagination search. help pls/.


nhojeinnor

Recommended Posts

i have a problem with my search pagination. when i click the pages. nothing happen.it just refresh the page. help pls.

 

 public function viewSearch($form)
    {                                  

    $affid         = $form['affid']; 
    $site_id       = $form['site_id'];      

    if($affid==""){        
    $where1 ="";          
    } else { 
    $where1 = "affid = '$affid'" ;
    }

    if($site_id==""){ 

    $where2 ="";   

    } elseif($affid=="" || site_id==""){

    $where2= "site_id =  $site_id"; 

    }else {    
    $where2 ="AND site_id = $site_id";  
    }                  
    $where_condition = $where1 . $where2;        
   
    $data = array();                             

    if ($affid=="" && $site_id=="")
    { 
    $count   = mysql_query("SELECT * FROM link ORDER BY site_id"); 
    $numrows = mysql_num_rows($count);
    $rowsperpage = 30;
    $totalpages = ceil($numrows / $rowsperpage);

    if (isset($_GET['page']) && is_numeric($_GET['page'])) {
    $currentpage = (int) $_GET['page'];
    } else {
    $currentpage = 1;
    }
    if ($currentpage > $totalpages) {
    $currentpage = $totalpages;
    }
    if ($currentpage < 1) {
    $currentpage = 1;
    }

    $offset = ($currentpage - 1) * $rowsperpage;

    $data = array();  
    
    $sql   = "SELECT * FROM link ORDER BY site_id LIMIT $offset, $rowsperpage"; 
    $result = mysql_query($sql) or die(mysql_error());   


    while(($rows = mysql_fetch_array($result)))
    {
    $data[] = $rows;
    }
    
    echo ' <b>Pages:</b> ';
    
    $range = 4;

    if ($currentpage > 1) {
    echo " <a href='{$_SERVER['PHP_SELF']}?page=1'>First</a> ";
    $prevpage = $currentpage - 1;
    echo " <a href='{$_SERVER['PHP_SELF']}?page=$prevpage'>Prev</a> ";
    }

    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
    if (($x > 0) && ($x <= $totalpages)) {
    if ($x == $currentpage) {
    echo " [<b>$x</b>] ";
    } else {
    echo " <a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> ";
    }
    } 
    }

    if ($currentpage != $totalpages) 
    {
    $nextpage = $currentpage + 1;
    echo " <a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>Next</a> ";
    echo " <a href='{$_SERVER['PHP_SELF']}?page=$totalpages'>Last</a> <br /><br /><br />";
    }              
    }    
      
    else 
    {  
    $count   = mysql_query("SELECT * FROM link  WHERE $where_condition ORDER BY site_id"); 
    $numrows = mysql_num_rows($count);
    $rowsperpage = 30;
    $totalpages = ceil($numrows / $rowsperpage);

    if (isset($_GET['page']) && is_numeric($_GET['page'])) {
    $currentpage = (int) $_GET['page'];
    } else {                        
    $currentpage = 1;
    }

    if ($currentpage > $totalpages) {
    $currentpage = $totalpages;
    }
    if ($currentpage < 1) {
    $currentpage = 1;
    }

    $offset = ($currentpage - 1) * $rowsperpage;

    $data = array();  
    
    $sql   = "SELECT * FROM link WHERE $where_condition ORDER BY site_id LIMIT $offset, $rowsperpage"; 
    $result = mysql_query($sql) or die(mysql_error());   


    while(($rows = mysql_fetch_array($result)))
    {
    $data[] = $rows;
    }
    
    echo ' <b>Pages:</b> ';
    
    $range = 3;

    if ($currentpage > 1) {
    echo " <a href='?page=1'>First</a> ";
    $prevpage = $currentpage - 1;
    echo " <a href='?page=$prevpage'>Prev</a> ";
    }

    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
    if (($x > 0) && ($x <= $totalpages)) {
    if ($x == $currentpage) {
    echo " [<b>$x</b>] ";
    } else {
    echo " <a href='?page=$x'>$x</a> ";
    }
    } 
    }

    if ($currentpage != $totalpages) 
    {
    $nextpage = $currentpage + 1;
    echo " <a href='?page=$nextpage'>Next</a> ";
    echo " <a href='?page=$totalpages'>Last</a> <br /><br /><br />";
    }
          
    }

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.