Welcome Guest, Not a member yet? Register   Sign In
help : CodeIgniter Search and pagination ?
#1

[eluser]ludo31[/eluser]
Hello ;
I need your help ;

I try to make a simple search with pagination and I have a problem that was discussed here :

http://www.devessence.com/2009/10/11/cod...-segments/

in my view file :

Code:
<?php echo form_open('annonce/rechercher');?>

     <label for="Province"> Faritra  : </label>
    
    
     <select name="province">
    
            <option value="0">Ataovy ny safidy</option>
            
            <optgroup label="Faritra">
                <option value="1">Antananarivo</option>
                  <option value="2">Antsiranana</option>
                  <option value="3">Fianarantsoa</option>
                  <option value="4">Mahajanga</option>
                  <option value="5">Toamasina</option>
                  <option value="6">Toliara</option>
            </optgroup>
     </select>
    
    
     <label for="Categorie" >Sokajy</label>
    
     <select name="categorie">
    
            <option value="0">Ataovy ny safidy</option>
            
            <optgroup label="Fiara-Moto ">
                <option value="1">Voitures (fiara)</option>
                  <option value="1">Motos</option>
                  <option value="1">Utilitaires (fiasana)</option>
                  <option value="1">Pieces Auto</option>
                  <option value="1">Pieces Moto</option>



                        
            </optgroup>
      
      </select>
   &lt;?php echo form_submit('envoyer', 'Karoy'); ?&gt;
  
   &lt;?php form_close();?&gt;

and in my controller :

Code:
public  function rechercher ()
{
      $province = $this->input->post('province');
      $categorie =  $this->input->post('categorie');
    
      //  $province = 1;
       // $categorie=1;
      
      
        $offset = $this->uri->segment(3);
            $limit = 2 ;
           $config['base_url']='http://localhost/MonSite/index.php/annonce/rechercher';
          
          
            $config['total_rows']= $this->annoncemodel->getRowAnnonceRecherche($province,$categorie);
            
            $config['num_links']=5;  
            
            $config['per_page']= $limit;
            
            $config['full_tag_open']='<div id="pagination">';
            
             $config['full_tag_close']='</div>';
            
             $config['next_link']='>>';
            
              $config['prev_link']='<<';
              
              $this->pagination->initialize($config);
              
              
              $data['infos'] = $this->annoncemodel->getAnnonceRecherche($province,$categorie,$config['per_page'],$offset);
              
            
          
           // var_dump($data);exit ;
      
      
      
      
              $this->load->view('principalannonce',$data);
              
              
      
      
      
      
      // $this->annoncemodel->getAnnonceRecherche ($province,$categorie,$limit ,$offset);

}

when I try to run it run and make the research but when I click on page 2 nothing !!

I think the problem is here :

Code:
$province = $this->input->post('province');
  $categorie =  $this->input->post('categorie');
    
      //  $province = 1;
       // $categorie=1;
      
      
        $offset = $this->uri->segment(3);

because when I try to change like that

Code:
//$province = $this->input->post('province');
  //$categorie =  $this->input->post('categorie');
    
        $province = 1;
       $categorie=1;
it works !! may be there is a conflict between uri->segment ans input->post

help me please I try to find a solution !!

thanks
#2

[eluser]aquary[/eluser]
It's not a conflict. There are no data posted when you click on the pagination links, which mean $province and $categories would always become FALSE after the first page. You have to also send both variables into the URI as well.

Code:
public  function rechercher ($province=0,$categories=0, $offset=0)
{
      // retrieve filter data if some filters are not available
      if(empty($provice))
          $province = $this->input->post('province');
      if(empty($categories))
          $categorie =  $this->input->post('categorie');

      // No need to use segment() since you can send it through URI directly
      // $offset = $this->uri->segment(3);
      $limit = 2 ;

      // try using site_url() instead, include the $province and $categories here
      $config['base_url']=site_url('annonce/rechercher/'.$province.'/'.$categories);
      $config['total_rows']= $this->annoncemodel->getRowAnnonceRecherche($province,$categorie);
      $config['num_links']=5;  
      $config['per_page']= $limit;
      $config['full_tag_open']='<div id="pagination">';
      $config['full_tag_close']='</div>';
      $config['next_link']='>>';
      $config['prev_link']='<<';
      $this->pagination->initialize($config);
      
      $data['infos'] = $this->annoncemodel->getAnnonceRecherche($province,$categorie,$config['per_page'],$offset);
      $this->load->view('principalannonce',$data);
}

Though not so effective when you have tons of filters available, this is the simplest one to make. Else, you'll have to store the filters inside a table or something similar.
#3

[eluser]ludo31[/eluser]
Thnaks for your reply ;

it shoes the second page but the problem is I can't return at the page 1

when I click on page 2

the url :

http://localhost/MonSite/index.php/annon...cher/1/1/2

and the current page stay at one
#4

[eluser]skunkbad[/eluser]
It's a lot easier to do a pagination with CI using ajax. The reason is that the form w/ search terms doesn't change, so as the pagination links are clicked on, the ajax request can just grab the form elements each time. There is no fallback to users who have javascript disabled, but if you want an example, check on the Manage Users page in Community Auth.
#5

[eluser]ludo31[/eluser]
Skunkbad can you explain more ??
I try with this Ajax library but it doesn't work

http://codeigniter.com/wiki/AJAX_Paginat...on_Library




Theme © iAndrew 2016 - Forum software by © MyBB