Jump to content

search pagination


nhojeinnor

Recommended Posts

pls help me with my codes. i am calling this function to a new php file. what i want to do is when the ELSE CONDITION execute. the pages will display and when i click the pages. prev12345next will direct to next page. but the problem is.. it redirects to my IF CONDITION. where the the IF CONDITION will display the total output of the data. when no input value on the searchbox.. and paginates the records.. pls help.. tnx..

 

 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=="")
    { 

    //max displayed per page
    $per_page = 30;

    //get start variable
    $start = $_GET['start'];

    //count max pages
    $max_pages = $record_count / $per_page; 

    if (!$start)
    $start = 0; 


    $count = mysql_num_rows(mysql_query("SELECT * FROM link ORDER BY site_id"));
    $sql   = "SELECT * FROM link ORDER BY site_id LIMIT $start, $per_page"; 
    $result = mysql_query($sql) or die(mysql_error());   


    while(($rows = mysql_fetch_array($result)))
    {
    $data[] = $rows;
    }

    $prev = $start - $per_page;
    $next = $start + $per_page;

    //show prev button
    if (!($start<=0))
    echo "<a href='{$_SERVER['PHP_SELF']}?start=$prev'>Prev</a> ";

    //set variable for first page
    $i=1;
    for ($x=0;$x<$count;$x=$x+$per_page)
    {
    if ($start!=$x)
    echo " <a href='{$_SERVER['PHP_SELF']}?start=$x'>$i</a> ";
    else
    echo " <a href='{$_SERVER['PHP_SELF']}?start=$x'>[$i]</a> ";
    $i++;
    }
    //show next button
    if (!($start>=$count-$per_page))
    echo "<a href='{$_SERVER['PHP_SELF']}?start=$next'>Next</a> ";                        

    }
      
    else  
    {        
    //max displayed per page
    $per_pages = 5;

    //get start variable
    $starts = $_GET['starts'];

    //count max pages
    $max_pages = $counts / $per_pages; 
  
    if (!$starts)
    $starts = 0; 

    $counts = mysql_num_rows(mysql_query("SELECT * FROM link WHERE $where_condition ORDER BY site_id"));
  
    $sql   = "SELECT * FROM link WHERE $where_condition ORDER BY site_id LIMIT $starts, $per_pages";
    $results = mysql_query($sql) or die(mysql_error());

     
    while(($rows = mysql_fetch_array($results)))
    {
    $data[] = $rows;
    }
    
    $prev = $starts - $per_pages;
    $next = $starts + $per_pages;

    //show prev button
    if (!($starts<=0))
    echo "<a href=\"?starts=$prev\">Prev</a> ";

    //set variable for first page
    $i=1;
    for ($x=0;$x<$counts;$x=$x+$per_pages)
    {
    if ($starts!=$x)
    echo " <a href=\"?starts=$x\">$i</a> ";
    else
    echo " <a href=\"?starts=$x\">[$i]</a> ";
    $i++;
    }
    
    //show next button
    if (!($starts>=$counts-$per_pages))
    echo "<a href=\"?starts=$next\">Next</a> ";                        

    }

  
    return $data;   
    
    }   

 

 

Link to comment
Share on other sites

  else  
    {        
    //max displayed per page
    $per_pages = 30;

    //get start variable
    $starts = $_GET['starts'];

    //count max pages
    $max_pages = $counts / $per_pages; 
  
    if (!$starts)
    $starts = 0; 

    $counts = mysql_num_rows(mysql_query("SELECT * FROM link WHERE $where_condition ORDER BY site_id"));
  
    $sql   = "SELECT * FROM link WHERE $where_condition ORDER BY site_id LIMIT $starts, $per_pages";
    $results = mysql_query($sql) or die(mysql_error());

     
    while(($rows = mysql_fetch_array($results)))
    {
    $data[] = $rows;
    }
    
    $prev = $starts - $per_pages;
    $next = $starts + $per_pages;

    //show prev button
    if (!($starts<=0))
    echo "<a href='?starts=$prev'>Prev</a> ";

    //set variable for first page
    $i=1;
    for ($x=0;$x<$counts;$x=$x+$per_pages)
    {
    if ($starts!=$x)
    echo " <a href='?starts=$x'>$i</a> ";
    else
    echo " <a href='?starts=$x'>[$i]</a> ";
    $i++;
    }
    
    //show next button
    if (!($starts>=$counts-$per_pages))
    echo "<a href='?starts=$next'>Next</a> ";                        

    }

 

this is my else part.. what i want is when it execute.. and the pages will pages is shown.. like 1 2 3 4 5 , when i click 2, i want the page to be turn on page 2. but what is does is redirect to my IF condition. this is the part.

  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=="")
    { 

    //max displayed per page
    $per_page = 30;

    //get start variable
    $start = $_GET['start'];

    //count max pages
    $max_pages = $record_count / $per_page; 

    if (!$start)
    $start = 0; 


    $count = mysql_num_rows(mysql_query("SELECT * FROM link ORDER BY site_id"));
    $sql   = "SELECT * FROM link ORDER BY site_id LIMIT $start, $per_page"; 
    $result = mysql_query($sql) or die(mysql_error());   


    while(($rows = mysql_fetch_array($result)))
    {
    $data[] = $rows;
    }

    $prev = $start - $per_page;
    $next = $start + $per_page;

    //show prev button
    if (!($start<=0))
    echo "<a href='{$_SERVER['PHP_SELF']}?start=$prev'>Prev</a> ";

    //set variable for first page
    $i=1;
    for ($x=0;$x<$count;$x=$x+$per_page)
    {
    if ($start!=$x)
    echo " <a href='{$_SERVER['PHP_SELF']}?start=$x'>$i</a> ";
    else
    echo " <a href='{$_SERVER['PHP_SELF']}?start=$x'>[$i]</a> ";
    $i++;
    }
    
    //show next button
    if (!($start>=$count-$per_page))
    echo "<a href='{$_SERVER['PHP_SELF']}?start=$next'>Next</a> ";                        

    }    

 

 

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.