Welcome Guest, Not a member yet? Register   Sign In
Concept Question
#1

[eluser]robert.fulcher[/eluser]
I have a form that submits for a search. I then get a listing page back. The listing page has links on it to a view page. I would like to have a link on the view page that would bring me back to the search results listing page. the search results is created through a submit function using post data. I can't set post data and link back to the submit function can I. The other solution is to create a new function to do the same search and read the uri string for the search variables.

What is the best way to do this?

Thanks
#2

[eluser]bretticus[/eluser]
Typically, folks just put the search parameters/variables in the url. note google.
#3

[eluser]pistolPete[/eluser]
A very common approach is the following:

1.) user submits the form
2.) redirect to search/results/{keyword}

Look at the forum search, it's done very similar.

controller:
Code:
class Search extends Controller {

    function do_search()
    {
        $this->load->helper('url');
        $keyword = $this->input->post('keyword')
        redirect('/search/results/'.$keyword);
    }
    
    function results($keyword)
    {
        // do the actual searching here
        // query db, load views, etc.
    }

}

view:
Code:
<form action="/search/do_search/" method="POST">
<input type="text" name="keyword" />
<input type="submit" value="Search!">
</form>
#4

[eluser]Vicente Russo[/eluser]
Hi,

I`ll post a piece of my code... but i`m in a hurry, so I can`t explaint too much...

Here we go:

Code:
function busca() { // Search function. Here I prepare the search URL to send to browser
        $termos = array();
        if ($this->uri->segment(4)!='') { // Here mi search is already made before
            $search = $this->uri->segment(4);
            $search = str_replace(' ','-',$search);
            acento_nao($search); // removing accents, custom function
            // Preparando array
            $aux = explode('-',$search);
            foreach($aux as $key => $valor) { // $termos will be each search word
                $termos[] = $valor;
            }
        } else { // Search form sent!
            $search = $this->input->post('valor');
            $search = str_replace(' ','-',$search);
            acento_nao($search);
            // Preparando array
            $aux = explode('-',$search);
            foreach($aux as $key => $valor) {
                $termos[] = $valor;
            }
        }
        redirect('administracao/admin/pagina/1/'.$search); // Redirecting to THIS controller and sending to pagination with page 1 as parameter
        
    }
    
        
    function pagina($page='',$termos='') { // Pagination function
        
        if ($page=='') {
            $this->session->keep_flashdata('mensagem');
            redirect('administracao/admin/pagina/1');
        }
        
        if ($this->uri->segment(5)!='') {
            $termos = $this->uri->segment(5);
        }
        
        $this->load->library('pagination');
        
        $limit = 20;
        $offset = ($page-1)*$limit;
    

        if ($termos=='') {
        
            $this->db->limit($limit, $offset);
            $query = $this->db->get('administradores');
            $data['total'] = $query->num_rows();
            $search = '';

        } else {
            $search = str_replace(' ','-',$termos);
            // Preparando array
            $busca = array();
            $aux = explode('-',$search);
            foreach($aux as $key => $valor) {
                $busca[] = $valor;
            }
            $this->db->like('nome', $busca[0]);
            $this->db->or_like('login', $busca[0]);
            $this->db->or_like('email', $busca[0]);
            
            $tt = count($busca);
            if ($tt>0) {
                for ($j=1;$j<$tt;$j++) {
                    $this->db->or_like('nome', $busca[$j]);
                    $this->db->or_like('login', $busca[$j]);
                    $this->db->or_like('email', $busca[$j]);
                }
            }
            
            
            $query_tt = $this->db->get('administradores');

            $this->db->like('nome', $busca[0]);
            $this->db->or_like('login', $busca[0]);
            $this->db->or_like('email', $busca[0]);

            $tt = count($busca);
            if ($tt>0) {
                for ($j=1;$j<$tt;$j++) {
                    $this->db->or_like('nome', $busca[$j]);
                    $this->db->or_like('login', $busca[$j]);
                    $this->db->or_like('email', $busca[$j]);
                }
            }
            
            $this->db->limit($limit, $offset);
            $query = $this->db->get('administradores');
            $data['total'] = $query_tt->num_rows();
        
        }
        
        

        $config['base_url'] = base_url().INDEX.'administracao/admin/pagina/';
        $config['total_rows'] = $data['total'];
        $config['per_page'] = $limit;
        $config['uri_segment'] = 4;
        $config['num_links'] = 5;
        
        
        $this->pagination->initialize($config);
        
        $data['status'] = 'listar';
        $data['search'] = $search;
        $data['range_min'] = $offset;
        $data['range_max'] = $search;
        $data['search'] = $search;
        $data['num_de_paginas'] = round($data['total'] / $limit);
        $data['adm'] = $query;
        
        $this->load->view('administracao/admin',$data);
        
        
    }




Theme © iAndrew 2016 - Forum software by © MyBB