Welcome Guest, Not a member yet? Register   Sign In
Pagination not passing the search parameters
#1

[eluser]bhakti.thakkar[/eluser]
Dear all,
i have implemented the pagination in my page. DB is MSSQL 2005. its working fine but now i want to implement it along with search parameters. it work fine on first page. but when the user clicks on the next link, the search parameters are not passed on to the next page. what am i missing
Model:
Code:
<?
class itc_model extends Model {

  function __Construct()
        {
            parent::Model();
        }

    function getItc($offset, $num)
    {
        return $this->_getItc($offset, $num);
    }

    function _getItc($offset, $num)
    {        
        $relation_id = $this->session->userdata('srelation_id');
        $Project_VC= $this->input->post('Project_VC');
        $Subprogram_ID= $this->input->post('Subprogram_ID');

        if ($Project_VC!='') {
            $srchstr = " and p.Project_VC like '%$Project_VC%' ";
        } else {
            $srchstr = "";
        }
    
        if ($Subprogram_ID!='') {
            $srchstr .= " and p.Project_id in ( select distinct(project_id) from project_subprogram_t where subprogram_id ='$Subprogram_ID' ) ";
        }

        $offset = (!$offset) ? 0 : $offset;
        $next = ($num + $offset);
        $curryr=date('Y');
        $prevyr=(date('Y')-1);
        $sql =
        'select * from (' .
        'select top ' . $num . ' * from (' .
        'select top ' . ($num+$offset-1) . ' p.Project_ID , p.Project_VC , a.InsertDate_DT , af.AttachedFile_VC , af.upfolder_VC , a.TransactionCertificate_ID from action_t a , project_t p , AttachedFile_Action_T aa , AttachedFile_T af where p.Relation_ID ='.$relation_id.' and a.actiontype_id=12 and a.deleted_dt is null and p.project_id = a.project_id and p.deleted_dt is null '.$srchstr.' and a.action_id = aa.action_id and aa.AttachedFile_ID = af.AttachedFile_ID and year(aa.InsertDate_DT) in ('.$curryr.' , '.$prevyr.') order by a.InsertDate_DT  desc) as t1 ' .
        ' order by InsertDate_DT asc) as t2 ' .
        ' order by InsertDate_DT desc';
        print $sql;
        $query = $this->db->query($sql);      
        return $query->result();
    }

    function ITCCount($Project_VC,$Subprogram_ID)
    {
                print "<br>";
        print "<br>";

        print "Project_VC = ".$Project_VC;
        print "<br>";
        print "Subprogram_ID = ".$Subprogram_ID;
                print "<br>";
        $relation_id = $this->session->userdata('srelation_id');
        if ($Project_VC!='') {
            $srchstr = " and p.Project_VC like '%$Project_VC%' ";
        } else {
            $srchstr = "";
        }
    
        if ($Subprogram_ID!='') {
            $srchstr .= " and p.Project_id in ( select distinct(project_id) from project_subprogram_t where subprogram_id ='$Subprogram_ID' ) ";
        }

        $curryr=date('Y');
        $prevyr=(date('Y')-1);
    
        $sql=" select  p.Project_ID , p.Project_VC , a.InsertDate_DT , af.AttachedFile_VC , af.upfolder_VC , a.TransactionCertificate_ID  from action_t a , project_t p , AttachedFile_Action_T aa , AttachedFile_T af where p.Relation_ID ='$relation_id' and a.actiontype_id=12 and a.deleted_dt is null and p.project_id = a.project_id and p.deleted_dt is null $srchstr and a.action_id = aa.action_id and aa.AttachedFile_ID = af.AttachedFile_ID and year(a.InsertDate_DT) in ('$curryr' , '$prevyr') ";
        print $sql."<br><br>";
        $numrows = $this->db->query($sql)->num_rows();
        return $numrows;

    }


}
?&gt;

Controller:
Code:
&lt;?
    function index()
    {        
        $Relation_ID = $this->session->userdata('srelation_id');
        $data['Project_VC'] = $this->input->post('Project_VC');
        $data['Subprogram_ID'] = $this->input->post('Subprogram_ID');
        $this->load->library('pagination');
        $start = (int) $this->uri->segment(3);    
        $config['per_page'] = 25;
        $data['query'] = $this->itc_model->getItc($start, $config['per_page']);        
        $config['total_rows'] = $this->itc_model->ITCCount($data['Project_VC'] , $data['Subprogram_ID']); // returns num rows
        $config['base_url'] = base_url().'index.php/itc/index/';
        $config['uri_segment'] = 3;

        $offset = (int) $this->uri->segment(3, 0);


        $config['full_tag_open'] = '<p class="pagination">';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);  
        $data['pagination'] = $this->pagination->create_links();

        $data['ListInfo'] = $this->itc_model->getListHelp();
        $data['Subprogram'] = $this->site_sentry->GeSubprogram_DD($this->input->post('Subprogram_ID') , " and subprogram_id in (select distinct subprogram_id from project_subprogram_t where project_id in (select project_id from project_t where relation_id ='$Relation_ID' and deleted_dt is null) and subprogram_id in (select subprogram_id  from subprogram_t where TransactionCertficate_BT=1 or ImportCertificate_BT =1))");

        if ($this->validation->run() == FALSE)
        {
            // grab existing certificates
            $data['page_title'] = 'Import / transaction certificates';
            $this->load->view('itc/index', $data);
        }
        else
        {
            redirect('');
        }
            
    }
#2

[eluser]TheFuzzy0ne[/eluser]
I don't have a great deal of experience with the pagination class, but I would imagine that you're be better off putting the page number at the end of your URL.

Code:
http://mysite.tld/some_controller/some_method/arg1/arg2/page_num

# As opposed to:

http://mysite.tld/some_controller/some_method/page_num/arg1/arg2
#3

[eluser]bhakti.thakkar[/eluser]
yes u are right and in addition to what you are saying i also found in this forum itself a thread http://ellislab.com/forums/viewthread/84344/ :

A few options:
1) My favorite: include the search term as a segment within the URI.
2) Use a Javascript library to unobtrusively stop the default action on the pagination links and rather, submit a hidden form with the original search term and the offset segment from the pagination link).
3) Probably the easiest: Set a session variable to hold the search term and use it if there is no term within the $_POST array

and i think the first option is the best.
but i am totally blank on how to pass this parameters to uri and how to use it

hope i get some help on it

Thanks
#4

[eluser]TheFuzzy0ne[/eluser]
Re: Option 1 - You can modify the URI by using a redirect, but you should be very wary, as some characters will trigger the dreaded "The URI you submitted has disallowed characters." error. In theory, using url_encode() should fix this, but it makes the URI look a bit messier, and still can have problems on some servers (for example, if it contains an encoded slash - /). Howeverm the first option will allow searches to be bookmarked.

Re: Option 2 - I'm not sure how this would work in an unobtrusive manner. What I mean is, how would it work if the user has JavaScript disabled?

Re: Option 3 - Yes, that's the simplest way to do it, but users won't be able to bookmark searches, and it relies on the user having cookies enabled.

Just my 2 pence. Smile
#5

[eluser]bhakti.thakkar[/eluser]
still not able to break through it. can anyone pass on a complete script (altleast all relative functions in the controller) of it. that would be really really helpful. time is really ticking off.
#6

[eluser]Thorpe Obazee[/eluser]
[email=http://stackoverflow.com/questions/227470/simple-search-passing-form-variable-to-uri]http://stackoverflow.com/questions/227470/simple-search-passing-form-variable-to-uri[/email]

This should be worth a try when searching.
#7

[eluser]TheFuzzy0ne[/eluser]
This hasn't been tested, but should hopefully illustrate the point.

some_view.php
Code:
&lt;html&gt;
    &lt;head&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;form action="/some_controller/search" method="post"&gt;
            <label for="search_word">
                Search word:<br />
                &lt;input type="text" name="search_word" id="search_word" /&gt;
            </label>
            &lt;input type="submit" name="submit" value="Search" /&gt;
        &lt;/form&gt;
    &lt;/body&gt;
&lt;/html&gt;

some_controller.php
Code:
class Some_controller extends Controller {

    function Some_controller()
    {
        parent::Controller();
    }

    function index()
    {
        $this->load->view('some_view');
    }

    function search()
    {
        redirect('/some_controller/show_results/' . $this->input->post('search_word'));
    }

    function show_results($search_word="")
    {
        echo "Searching for $search_word";
    }
}

Hope this helps.
#8

[eluser]bhakti.thakkar[/eluser]
hello TheFuzzy0ne,
in the above code do i need to pass the pagination code in both show_results() and index()?
#9

[eluser]bhakti.thakkar[/eluser]
http://www.vrusso.com.br/blog/?tag=codei...anguage=en
i have also given a try to above link but no success till now. in fact first page pagination also vanished. in real pains
i have added the new pagination class to application/library and below is my code

Controller:
Code:
//itc/page/numrows/project_vc/Subprogram_ID
    function index()
    {        
        redirect('itc/page/1');
    
    }
        function search() {
        
            if ($this->uri->segment(4)!='') {
                $Project_VC= $this->uri->segment(4);

            } elseif ($this->uri->segment(5)!='') {
               $Subprogram_ID= $this->uri->segment(5);
            }
            redirect('itc/page/1/'.$Project_VC.'-'.$Subprogram_ID);
        
        }
    
    function page($page='' , $Project_VC='' , $Subprogram_ID='') {
        $Relation_ID = $this->session->userdata('srelation_id');
        if ($page=='') {
              redirect('itc/page/1');
        }  
        
         $this->load->library('pagination');
        $config['per_page'] = 25;
          $start = (int) $this->uri->segment(3);    

          if ($Project_VC='' && $Subprogram_ID='') {
                $data['query'] = $this->itc_model->getItc($start, $config['per_page'] ,$Project_VC , $Subprogram_ID);        
                $data['total_rows'] = $this->itc_model->ITCCount($Project_VC , $Subprogram_ID);
            } else {
        


                $data['query'] = $this->itc_model->getItc($start, $config['per_page'] ,  $Project_VC,$Subprogram_ID);        
                $data['total_rows'] = $this->itc_model->ITCCount( $Project_VC,$Subprogram_ID);
            }
        $config['base_url'] = base_url().'index.php/itc/page/';
        $config['uri_segment'] = 4;
        $offset = (int) $this->uri->segment(4, 0);


        $config['full_tag_open'] = '<p class="pagination">';
        $config['full_tag_close'] = '</p>';
        $this->pagination->initialize($config);  
        $data['pagination'] = $this->pagination->create_links();
        $data['ListInfo'] = $this->itc_model->getListHelp();
        
        
        $data['Project_VC']=     $Project_VC;
        $data['Subprogram_ID']= $Subprogram_ID;


        $data['Subprogram'] = $this->site_sentry->GeSubprogram_DD($this->input->post('Subprogram_ID') , " and subprogram_id in (select distinct subprogram_id from project_subprogram_t where project_id in (select project_id from project_t where relation_id ='$Relation_ID' and deleted_dt is null) and subprogram_id in (select subprogram_id  from subprogram_t where TransactionCertficate_BT=1 or ImportCertificate_BT =1))");

        $data['page_title'] = 'Import / transaction certificates';

        $this->load->view('itc/index', $data);
            
    }

Model:
Code:
function getItc($offset, $num, $Project_VC,$Subprogram_ID)
    {
        return $this->_getItc($offset, $num , $Project_VC,$Subprogram_ID);
    }




    function _getItc($offset, $num , $Project_VC,$Subprogram_ID)
    {        
        $relation_id = $this->session->userdata('srelation_id');

        if ($Project_VC!='') {
            $srchstr = " and p.Project_VC like '%$Project_VC%' ";
        } else {
            $srchstr = "";
        }
    
        if ($Subprogram_ID!='') {
            $srchstr .= " and p.Project_id in ( select distinct(project_id) from project_subprogram_t where subprogram_id ='$Subprogram_ID' ) ";
        }

        $offset = (!$offset) ? 0 : $offset;
        $next = ($num + $offset);
        $curryr=date('Y');
        $prevyr=(date('Y')-1);
        $sql =
        'select * from (' .
        'select top ' . $num . ' * from (' .
        'select top ' . ($num+$offset-1) . ' p.Project_ID , p.Project_VC , a.InsertDate_DT , af.AttachedFile_VC , af.upfolder_VC , a.TransactionCertificate_ID from action_t a , project_t p , AttachedFile_Action_T aa , AttachedFile_T af where p.Relation_ID ='.$relation_id.' and a.actiontype_id=12 and a.deleted_dt is null and p.project_id = a.project_id and p.deleted_dt is null '.$srchstr.' and a.action_id = aa.action_id and aa.AttachedFile_ID = af.AttachedFile_ID and year(aa.InsertDate_DT) in ('.$curryr.' , '.$prevyr.') order by a.InsertDate_DT  desc) as t1 ' .
        ' order by InsertDate_DT asc) as t2 ' .
        ' order by InsertDate_DT desc';
        print $sql;
        $query = $this->db->query($sql);      
        return $query->result();
    }


    function ITCCount($Project_VC,$Subprogram_ID)
    {
        print "<br>";
        print "<br>";

        print "Project_VC = ".$Project_VC;
        print "<br>";
        print "Subprogram_ID = ".$Subprogram_ID;
                print "<br>";
        $relation_id = $this->session->userdata('srelation_id');
        if ($Project_VC!='') {
            $srchstr = " and p.Project_VC like '%$Project_VC%' ";
        } else {
            $srchstr = "";
        }
    
        if ($Subprogram_ID!='') {
            $srchstr .= " and p.Project_id in ( select distinct(project_id) from project_subprogram_t where subprogram_id ='$Subprogram_ID' ) ";
        }

        $curryr=date('Y');
        $prevyr=(date('Y')-1);
    
        $sql=" select  p.Project_ID , p.Project_VC , a.InsertDate_DT , af.AttachedFile_VC , af.upfolder_VC , a.TransactionCertificate_ID  from action_t a , project_t p , AttachedFile_Action_T aa , AttachedFile_T af where p.Relation_ID ='$relation_id' and a.actiontype_id=12 and a.deleted_dt is null and p.project_id = a.project_id and p.deleted_dt is null $srchstr and a.action_id = aa.action_id and aa.AttachedFile_ID = af.AttachedFile_ID and year(a.InsertDate_DT) in ('$curryr' , '$prevyr') ";
        print $sql."<br><br>";
        $numrows = $this->db->query($sql)->num_rows();
        return $numrows;

    }
#10

[eluser]TheFuzzy0ne[/eluser]
My code was only meant to illustrate how you can take arguments from the post array and insert them into the URI. The rest is up to you. Smile




Theme © iAndrew 2016 - Forum software by © MyBB