duan0821 2016-01-20 00:17
浏览 31

在Codeigniter中首次分页后,不会显示搜索结果

I am new to Codeigniter and seeking some help here.

I am making a test app with pagination. It works fine until the first result but when clicked on 'Next' or 'Any Pagination' tells no results were found.

I think it calls for url alright but don't know what else is the problem.

http://localhost/admin/search/search-results/2

My controller:

public function pagination(){
$keyword = $this->input->post('search[1]');
$main_keyword = $this->search_model->get_city_id_by_input($keyword);

    $config['base_url'] = base_url().'search/search-results/';
    $config['total_rows'] = $this->search_model->total_number_of_rows($main_keyword);
    $config['per_page'] = 1;
    $config['use_page_numbers'] = TRUE;
    $config['num_links'] = $this->search_model->total_number_of_rows($main_keyword);
    $config['cur_tag_open'] = ' ';
    $config['next_link'] = 'Next';
    $config['prev_link'] = 'Previous';

$this->pagination->initialize($config);
$data['results'] = $this->search_model->get_search_results($main_keyword, $config['per_page'], $this->uri->segment(3));

    $this->load->view('view',$data);
}

Model:

function get_city_id_by_input($keyword){
    $this->db->select('id');
    $this->db->from('vbc_city');
    $this->db->where('v_city_name', $keyword);
    $query = $this->db->get();
    $query_result = $query->result_array();
    return $query_result();
}
  public function total_number_of_rows($main_keyword) {
      $this->db->select('vbc_item_id');
      $this->db->from('vbc_vacation_item_attri');
      $this->db->where('v_item_city', $main_keyword);
      $query = $this->db->get();
      return $query->num_rows();
}
  public function get_search_results($main_keyword, $perpage, $offset) {
      $this->db->select('*');
      $this->db->from('vbc_vacation_item_attri');
      $this->db->where('v_item_city', $main_keyword);
      $this->db->limit($perpage, $offset);
      $query = $this->db->get();
      $result = $query->result();
      return $result;
    }

Please help.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
    • ¥15 划分vlan后,链路不通了?
    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据