0
votes

I have a problem with pagination and codeigniter. I have a quick_searh view from witch I am submitting the information to a index controller function and there setting the pagination and calling the quick_search method to get the data I want. It just doesnt work . I've spent more then 5 hours rewriting those methods and even starting with quick_search and then passing to index function but nothing worked, please help.

    public function index(){

    // search parameters config
    $lawyer_name = $this->input->post('lawyer_name');
    $kanzlei = $this->input->post('kanzlei');
    $area_of_expertise = $this->input->post('area_of_expertise');
    $post_code = $this->input->post('post_code');
    $city = $this->input->post('city');

    $result = $this->quick_search(
        $this->uri->segment(3),
        $lawyer_name,
        $kanzlei,
        $area_of_expertise,
        $post_code,
        $city);

    if(isset($result)){
        // pagination config
        $this->load->library('pagination');
        $this->load->library('table');

        $config['total_rows'] = count($result);
        $config['base_url'] = 'http://localhost/anwalt/index.php/search/index';
        $config['per_page'] = 5;
        $config['num_links'] = 5;

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

        $data['search_result_array'] = $result;
        $data['main_content'] = 'pages/quick_search_results';
        $this->load->view('templates/home_body_content', $data);
    }
}

the quick_search function:

    public function quick_search($offset, $lawyer_name, $kanzlei, $area_of_expertise, $post_code, $city){

    // no input in the quick search
    if( empty($lawyer_name) && empty($kanzlei) && empty($area_of_expertise)
        && empty($post_code) && empty($city))
    {
        $result = 'nothing';

    } else {

        $this->load->model('quick_search_model');
        $result = $this->quick_search_model->get_search_results(
            $offset,
            $lawyer_name,
            $kanzlei,
            $area_of_expertise,
            $post_code,
            $city
            );
    }

    return $result;
}

the sql is like this:

$sql = "SELECT users.user_id, users.canonical_name, first_name, last_name, city, phone_number, kanzlei
    from users
    inner join user_normal_aos
    on users.user_id = user_normal_aos.user_id
    inner join normal_areas_of_expertise
    on user_normal_aos.normal_areas_of_expertise_id = normal_areas_of_expertise.normal_areas_of_expertise_id
    where ".implode(" AND ", $where);

    if(empty($offset)){
        $offset = 0;
    }

    $sql = $sql." LIMIT ".$offset.", 4";

The data are displayed but I dont see the pagination in there .. and even when I want to change the url for segmenting it says I dont have any data.

The view is like:

<h1>Quick search results</h1>
<?php 
if($search_result_array == "nothing"){
    echo "<h3>You havent inputed anything</h3>";    
} else {
    echo $this->table->generate($search_result_array);
}
echo $this->pagination->create_links();
2

2 Answers

1
votes

As per your search variables you can use this:

$lawyer_name = $this->input->post('lawyer_name');
$kanzlei = $this->input->post('kanzlei');
$area_of_expertise = $this->input->post('area_of_expertise');
$post_code = $this->input->post('post_code');
$city = $this->input->post('city');

/*pagination start*/
$this->load->library('pagination');
$config['base_url']         = base_url().'index.php/index/lawyer/'.$lawyer_name.'/kanzlei/'.$kanzlei.'/area_of_expertise/'.$area_of_expertise.'/post_code/'.$city.'/page/';
$config['total_rows']       = $this->model->count_all_results();    ###implement this function to count all the vodeos as per the search variables, just use the same function as "quick_search" but without the limit clause
$config['per_page']         = count($result);;
$config['uri_segment']      = 10;
$config['next_link']        = 'Next';
$config['prev_link']        = 'Prev';
$config['cur_tag_open']     = '<span class="active_page">';
$config['cur_tag_close']    = '</span>';
$this->pagination->initialize($config);
/*pagination end*/
0
votes

You can not use $this->pagination->create_links(); method in view.

Use $data['pagination'] = $this->pagination->create_links(); in controller just before loading view and echo $pagination in view

hope this will help you.