Welcome Guest, Not a member yet? Register   Sign In
How to keep a value while the page refresh ?
#1

[eluser]ludo31[/eluser]
Hi guys , I have really a problem that I try to solve since 2 days :

I would like to create a search page and the result will show in the same page so : in order to make it simple : in my view :

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>
            <optgroup label="Immobilier-Trano">
                <option value="2">Ventes (Hamidy)</option>
                <option value="2">Locations (Ahofa)</option>
                <option value="2">Colocations (hiarahana)</option>
                <option value="2">Bureaux (birao)</option>
                
                
            </optgroup>
             <optgroup label="T&eacute;l&eacute;phonie">
                
                <option value="3">T&eacute;l&eacute;phones-accessoires </option>
                
                
             </optgroup>
            
             <optgroup label="Multimedia">
                <option value="4">Jeux video-console</option>
                 <option value="4">Ordinateur-informatique</option>
                  <option value="4">TV-Son-iPod</option>
                   <option value="4">CD-DVD-Livre</option>
                
             </optgroup>
             <optgroup label="Maison (Fanaka)">
                
                <option value="5">Ameublement</option>
                 <option value="5">El&eacute;ctrom&eacute;nager</option>
             </optgroup>
            
             <optgroup label="Modes">
                <option value="6">Chaussures (kiraro)</option>
                <option value="6">Montres et bijoux (firavaka)</option>
                <option value="6">V&ecirc;tements (akanjo)</option>
                
                
             </optgroup>
            
             <optgroup label="Autres (hafa)">
                <option value="7"> Autres (hafa)</option>
                
             </optgroup>
            
  
            
     </select>
    

     &lt;?php echo form_submit('envoyer', 'Karoy'); ?&gt;
                    
        &lt;?php  echo form_close();?&gt;

and in my controller ; where the big problem is I don't know to keep the value of input post or I don't know what's wrong with offset because the pagination work but when I try to click on page 2 nothing in the page the discussion has been evoke here http://ellislab.com/forums/viewthread/151977/
and I try to make the same as he recommends
here is my controller

Code:
public function rechercher ()
{

  


     /* ici je tente de les recuperer */
       $province=$this->input->post('province');
       if(strlen($province)>0){
           $this->session->set_userdata('province',$province);
       }
      
       $province = $this->session->userdata('province');
      
      
       $categorie=$this->input->post('categorie');
       if(strlen($province)>0){
           $this->session->set_userdata('categorie',$categorie);
       }
      
       $categorie = $this->session->userdata('categorie');
      
      
      
      
      
      
       /* necessaire pour la pagination */
     $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);
              
            
          
          
             /*on l'envoie à la vue de nouveau */      
      
      
      
              $this->load->view('principalannonce',$data);
              
              
      
      
      
      


}

please do you have an idea ???

thanks
#2

[eluser]Ninjabear[/eluser]
I can only see one thing, you have no:

Code:
$config['uri_segment'] = 3; //Set to value of offset.
#3

[eluser]ludo31[/eluser]
[quote author="Ninjabear" date="1332498449"]I can only see one thing, you have no:

Code:
$config['uri_segment'] = 3; //Set to value of offset.
[/quote]

Hi , thanks for your response but this code don't suffice ???

Code:
$offset = $this->uri->segment(3);
#4

[eluser]Ninjabear[/eluser]
[quote author="ludo31" date="1332501069"][quote author="Ninjabear" date="1332498449"]I can only see one thing, you have no:

Code:
$config['uri_segment'] = 3; //Set to value of offset.
[/quote]

Hi , thanks for your response but this code don't suffice ???

Code:
$offset = $this->uri->segment(3);
[/quote]

No because $offset is just a variable and isn't picked up by the pagination class. The pagination initialise function needs to know where to stick the offset part.
#5

[eluser]InsiteFX[/eluser]
Code:
$data['infos'] = $this->annoncemodel->getAnnonceRecherche($province,$categorie,$config['per_page'],$this->uri->segment(3));
#6

[eluser]ludo31[/eluser]
thank you so much guy it works for someone who have the same problem I proceed like that

Code:
public function rechercher ()
{

  


     /* ici je tente de les recuperer */
       $province=$this->input->post('province');
       if(strlen($province)>0){
           $this->session->set_userdata('prov',$province);
       }
      
       $province2 = $this->session->userdata('prov');
      
      
       $categorie=$this->input->post('categorie');
       if(strlen($province)>0){
           $this->session->set_userdata('cate',$categorie);
       }
      
       $categorie2 = $this->session->userdata('cate');
      
      
       $config['uri_segment']=3;
      
      
      
       /* necessaire pour la pagination */
     $offset = $this->uri->segment(3);
            $limit = 2 ;
      
      
           $config['base_url']='http://localhost/MonSite/index.php/annonce/rechercher';
          
      $config['per_page']= $limit;
          
            $config['total_rows']= $this->annoncemodel->getRowAnnonceRecherche($province2,$categorie2);
            
                 $data['infos'] = $this->annoncemodel->getAnnonceRecherche($province2,$categorie2,$config['per_page'],$offset);
            
       /* pgination */
            
            $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);
        
            
          
             /*on l'envoie à la vue de nouveau */      
                
                
              
      
                
                



            $this->pagination->initialize($config);
            $data['pag_links'] = $this->pagination->create_links();
            
            
    
      
      
              $this->load->view('principalannonce',$data);
              
              
      
      
      
      


}

so I must change the name of the variable here

$categorie2 = $this->session->userdata('cate');

thank you so much

#7

[eluser]Ninjabear[/eluser]
[quote author="InsiteFX" date="1332506484"]
Code:
$data['infos'] = $this->annoncemodel->getAnnonceRecherche($province,$categorie,$config['per_page'],$this->uri->segment(3));
[/quote]

I really didn't understand this because there was just a line of code and no explanation. If this line is incorrect I don't know why and I can't read it because I don't speak the language.
#8

[eluser]InsiteFX[/eluser]
What do you not get with this code?
Code:
// $config['per_page'] = LIMIT
// $this->uri->segment(3)) = OFFSET to start at
$data['infos'] = $this->annoncemodel->getAnnonceRecherche($province,$categorie,$config['per_page'],$this->uri->segment(3));
#9

[eluser]ludo31[/eluser]
[quote author="InsiteFX" date="1332707411"]What do you not get with this code?
Code:
// $config['per_page'] = LIMIT
// $this->uri->segment(3)) = OFFSET to start at
$data['infos'] = $this->annoncemodel->getAnnonceRecherche($province,$categorie,$config['per_page'],$this->uri->segment(3));
[/quote]
of course it is the same result :

Code:
$data['infos'] = $this->annoncemodel->getAnnonceRecherche($province2,$categorie2,$config['per_page'],$this->uri->segment(3));

and

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

Code:
$data['infos'] = $this->annoncemodel->getAnnonceRecherche($province2,$categorie2,$config['per_page'],$offset);


for explain :

in my model I have something like that :

Code:
public  function getAnnonceRecherche ($province,$categorie,$limit ,$offset)
{
    $this->db->select('idannonce,nom_path,prix,nom_categorie,nom_ville,titre');
     $this->db->from('annonce');
     $this->db->join('ville', 'ville.idville = annonce.identifiant_ville');
     $this->db->join('categorie', 'categorie.idcategorie = annonce.identifiant_categorie');
     $this->db->join('image', 'image.identifiant_annonce = annonce.idannonce');
    
      $this->db->where('identifiant_categorie', $categorie);
      $this->db->where('identifiant_region', $province);
    
    
     $this->db->order_by("idannonce", "desc");
       $this->db->limit($limit,$offset);
      
      
     $query = $this->db->get();
    
     if($query->num_rows()>0)
      {
       foreach($query->result_array()as $row)
        {
         $data[] = $row;
        }
        
      
                          
        return $data;
     }
      
      
}

so we nedd to pass parameter in function getAnnonceRecherche ($province,$categorie,$limit ,$offset)
#10

[eluser]Ninjabear[/eluser]
[quote author="InsiteFX" date="1332707411"]What do you not get with this code?
Code:
// $config['per_page'] = LIMIT
// $this->uri->segment(3)) = OFFSET to start at
$data['infos'] = $this->annoncemodel->getAnnonceRecherche($province,$categorie,$config['per_page'],$this->uri->segment(3));
[/quote]

French? Again, you didn't explain anything.




Theme © iAndrew 2016 - Forum software by © MyBB