Welcome Guest, Not a member yet? Register   Sign In
Pagination and _post variable
#1

[eluser]bianchi[/eluser]
Friends,

How can i hold the _post variable on the pagination..

for example :
when the search happened..

the keyword (_post) = woody

page 2 :
i got :
http://localhost/perfumeshop/perfumes/search/woody/5

but if i clicked page 2,

the url on pagination link lost the woody and will query all of the table...

for example page 3 :
http://localhost/perfumeshop/perfumes/se...0......the keywords "woody" had gone..

How can I keep the keyword ? so my search result can be paginated well...

Thanks
my controller :
Code:
function search(){
            $this->load->helper('html');
            
                 //load pagination class
          $this->load->library('pagination');
          $this->load->library('session');
              
            $this->load->model('perfumes_model');
            
            //$display = $this->input->post('keyword',TRUE);
            
             $display              = $_POST['keyword'];
       //$_SESSION['display']  = $display;
       //$word = $_SESSION['display'];
            /*$displays = array(
                            'keyword' => $this->input->post('keyword'));
                            
            foreach ($displays as $display)
                {
                    //echo $display;
              }
              */
              //echo $word;
            //$this->session->set_userdata('display', $display);  //set value
            //$url = $this->session->userdata('display'); //retrieve value                                                
            //echo $url;
            
            //echo $display;
            
            // Pengaturan konfigurasi untuk pagination
              
              $total_rows = $this->db->query("SELECT COUNT(*) AS total FROM perfumeemporium_general WHERE `description` LIKE '%$display%' ")->row_array();
              
            $config['base_url'] = base_url().'perfumes/search/'.$display;
               //$config['total_rows'] = $this->db->count_all('perfumeemporium_general');
               $config['total_rows'] = $total_rows['total'];
            $config['per_page'] = '5';
            $config['first_link'] = 'First';
            $config['last_link'] = 'Last';
            $config['next_link'] = 'Next';
            $config['prev_link'] = 'Previous';
            $config['uri_segment'] = 4;
            $this->pagination->initialize($config);
            
                
            // Pengaturan konfigurasi untuk pagination
            
            // Query data using model
            //$data['query'] = $this->perfumes_model->perfumes_search_description($display);
            $data['query'] = $this->perfumes_model->perfumes_search_description($display,$this->uri->segment(4,0),$config['per_page']);
            //$this->load->vars($data);
            $this->load->view('perfumes_main',$data);              
                
        }
Model :
Code:
function perfumes_search_description($display,$offset,$num)
      {
          //$this->db->where('name', $name);
            $this->load->database();
            $query = $this->db->query("SELECT * FROM perfumeemporium_general WHERE `description` LIKE '%$display%' ORDER BY `type` LIMIT $offset,$num");
            //$query = $this->db->query("SELECT * FROM perfumeemporium_general WHERE `description` LIKE '%$display%' ORDER BY `type`");
      
            //$query = $this->db->get_where('perfumeemporium_general', array('description' => $display),$num,$offset);
            return $query->result();
            //echo $this->db->last_query();
            //echo $query;
            //$this->output->enable_profiler(true);
      }


Thank you all
#2

[eluser]mddd[/eluser]
The problem is that you are getting the search word from $_POST. After clicking a link from pagination, the $_POST is no longer there. But the search word IS in the url, after 'search' ! You could check to see if there is a search word in $_POST, and if it is not there, look in $this->uri->segment(3) to see if the word is there!
#3

[eluser]bianchi[/eluser]
i found blank screen when i did this :
echo $this->uri->segment(3);

what should i do?
#4

[eluser]bianchi[/eluser]
[quote author="bianchi" date="1275313145"]i found blank screen when i did this :
echo $this->uri->segment(3);

what should i do?[/quote]

and I got 0

when i invoked this :
echo $this->uri->segment(4,0);

what should i change ?
#5

[eluser]mddd[/eluser]
At first, the keyword will be in $_POST and not in the url.. But after you click a link from your pagination, it will be in the url and not in $_POST. Like so: /perfumes/search/searchword/2.

So your code could be like:
Code:
// check if keyword is in $_POST. if not, check the uri.
$display = $this->input->post('keyword');

if (!$display)
   $display = $this->uri->segment(3);

if (!$display)
   // maybe the user has not searched yet. do something to show the search form.
#6

[eluser]bianchi[/eluser]
it works, thank you very much my friend
You can see the result :
http://perfumeshop.rickoshop.com/perfume.../Hilton/10

or see the search :
http://perfumeshop.rickoshop.com

Thanks again...Smile




Theme © iAndrew 2016 - Forum software by © MyBB