drkxgs9358 2013-02-20 05:58
浏览 31

显示来自数据库的搜索结果,但结果分页不能在codeigniter中工作?

search results from database are displayed but on that results pagination not working in codeigniter? Hello to all, I am using codeigniter i have one text field in my view page when user enter any name in that field related with my database table 'deals' the deals match with entered field are displayed but on that pagination links not working .when i click on 2nd page link it just blinks as i use ajax,i also apply session on entered term,but cant get what to do now?

here my controller

class Pagesearch extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
        $this->load->model('searchmodel');
                $this->load->helper('url');
        // Load Pagination
        $this->load->library('pagination');
                $this->load->library('session');
    }


     public function index($offset = 0)
         {

               $pagination_per_page = 3;


           $config['base_url'] = base_url().'pagesearch/index/';
               $config['per_page'] = $pagination_per_page;
              $search_term = $this->searchmodel->searchterm_handler($this->input->post('tsd'));

               $config['total_rows'] = count($this->searchmodel->get_results($search_term));

               $config['uri_segment'] = 3;
           $config['use_page_numbers'] = TRUE;            
           $this->pagination->initialize($config);



         $data['deals_data'] = $this->searchmodel->get_results($search_term, $pagination_per_page, (($offset != 0)?( $pagination_per_page * ($offset - 1)): 0));
         $this->load->view('deals/jsonsearch',$data);


        }

here it is my model 

<?php
class Searchmodel extends CI_Model {

    public function __construct()
    {
        $this->load->database();

    }

        public function get_results($search_term, $limit, $offset)
    {

        $this->db->select('*');
        //$this->db->from('deals');
        $this->db->like('name',$search_term);
        $query = $this->db->get('deals',$limit,$offset);
        return $query->result_array();
        }

        public function searchterm_handler($search_term)
        {
            if($search_term)
            {
            $this->session->set_userdata('tsd', $search_term);
            return $search_term;
            }
            elseif($this->session->userdata('tsd'))
            {
            $search_term = $this->session->userdata('tsd');
            return $search_term;
            }
            else
            {
            $search_term ="";
            return $search_term;
            }
        }


}

and this is view to display

<div id="dealsData">
    <?php foreach ($deals_data as $data): ?>
         //some code here to diplay

<?php endforeach ?>
    <div id="pagination">
        <?php echo $this->pagination->create_links(); ?>
    </div>

</div>

so please anybody who can go through this stuff searching results with pagination using ajax in codeigniter please give some time & solution for me ?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解 yolo算法问题
    • ¥15 虚拟机打包apk出现错误
    • ¥30 最小化遗憾贪心算法上界
    • ¥15 用visual studi code完成html页面
    • ¥15 聚类分析或者python进行数据分析
    • ¥15 逻辑谓词和消解原理的运用
    • ¥15 三菱伺服电机按启动按钮有使能但不动作
    • ¥15 js,页面2返回页面1时定位进入的设备
    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。