Codeigniter搜索与分页不起作用

I have a search form with 3 fields, cargo_oferta, nome_oferta and local_oferta, the other 2 data_oferta and id_oferta are set from the database and outputted to the template.

I have pagination that is not working. I have to validate the form so when the form is false or null it gives all the values in the table (search by "a" soething like %."a".%) and when its true it searches by the 3 form fields.

The problem is the first time I click the pagination (page 2) for one filled field ex: "xgf" it gives: http://localhost/site/index.php/main_controller/index/2/xgf/ the second time I click pagination (ex: page 3) it gives: http://localhost/site/index.php/main_controller/index/32/xgf/ and keeps putting the pagination numbers before 32 and after index, incrementing the url...?

I see 2 problems (this last one) and "xfg" was the 2nd field "nome_empresa" and becuase the other apear blank the first time I click it "passes" to the first position in the url it should be "something"/xgf/"something" and not "/xgf/"

The controller:

public function index($cargo_oferta = null,$nome_empresa = null,$local_oferta = null) {

    $this->form_validation->set_rules('data_oferta','Cargo oferta','trim', 'xss_clean');
    $this->form_validation->set_rules('cargo_oferta','Cargo oferta','trim', 'xss_clean');
    $this->form_validation->set_rules('nome_empresa','Nome empresa','trim', 'xss_clean');
    $this->form_validation->set_rules('local_oferta','Local oferta','trim', 'xss_clean');
    $this->form_validation->set_rules('id_oferta','Local oferta','trim', 'xss_clean');

    if ($this->form_validation->run() == FALSE)
    {

        $data = array(
                'anuncio' => 'template/template'
        );
        $config['suffix'] = $cargo_oferta.'/'.$nome_empresa.'/'.$local_oferta;

        $config['base_url'] = base_url().'index.php/main_controller/index/';
        $config['total_rows'] = $this->main_model->count();
        $config['per_page'] = 5;

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

        $data["info"] = $this->main_model->index($config["per_page"], $page, 
            $data_oferta = '', $cargo_oferta = 'a', 
            $nome_empresa = 'a', $local_oferta = 'a',
            $id_oferta = 'a');

    }
    else    // form validation true
    {

        $data_oferta = $this->input->post('data_oferta');

        $cargo_oferta = $this->input->get_post('cargo_oferta');
        $nome_empresa = $this->input->get_post('nome_empresa');
        $local_oferta = $this->input->get_post('local_oferta');

        $id_oferta = $this->input->post('id_oferta');

        $data = array(
                'anuncio' => 'template/template'
        );

        $config['suffix'] = $cargo_oferta.'/'.$nome_empresa.'/'.$local_oferta;

        $config['base_url'] = base_url().'index.php/main_controller/index/';

        $config['total_rows'] = $this->main_model_count->index(
            $data_oferta,
            $cargo_oferta,
            $nome_empresa,
            $local_oferta,
            $id_oferta);
        $config['per_page'] = 5;

        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

        $data["info"] = $this->main_model->index($config["per_page"], $page,
            $data_oferta, $cargo_oferta,
            $nome_empresa, $local_oferta,
            $id_oferta);

        $data["a_link"] = $config['base_url'];

    }       

    $config['num_links'] = 2;
    $config["uri_segment"] = 3;
    $config['use_page_numbers'] = TRUE;


    $this->pagination->initialize($config);

    $data["links"] = $this->pagination->create_links();

    $data["number"]=$this->main_model->count();

    $this->load->view('template/header_index');
    $this->load->view('template/template', $data);
    $this->load->view('template/footer_visual');
    $this->load->view('template/footer');

}   

// main_model_count counts the resulting rows for the search
// main_model gives the results and counts the total number of rows

public function search_anuncios(
        $limit,
        $start,

        $data_oferta,
        $cargo_oferta,
        $nome_empresa,
        $local_oferta,
        $id_oferta
){

    $sql = "SELECT
    empregos.id_oferta,

    empregos.data_oferta,
    empregos.imagem_oferta,
    empregos.cargo_oferta,
    empregos.descricao_oferta,
    empregos.observacoes_oferta,
    empregos.perfil_oferta,
    empregos.local_oferta,

    users.id,
    users.nome_empresa
    FROM trabalho.empregos
    JOIN trabalho.users
    ON empregos.id = users.id

    WHERE empregos.data_oferta LIKE ?
    OR empregos.cargo_oferta LIKE ?
    OR users.nome_empresa LIKE ?
    OR empregos.local_oferta LIKE ?
    OR empregos.id_oferta LIKE ?
    ORDER BY empregos.data_oferta DESC

    limit $start,$limit
    ;";


    $variaveis_form = array(
            $data_oferta,
            $cargo_oferta,
            $nome_empresa,
            $local_oferta,
            $id_oferta
    );

    $q = $this->db->query($sql,$variaveis_form);

    return $q->result();

}