大家好。我在使用GET方法分页时遇到了麻烦。这是问题所在。这是我的链接http://localhost/eshoppy/Search/?search=nike但是当我点击下一个按钮时,搜索变量就会成为http://localhost/eshoppy/Search/?search=nike/3,因此不会有nike / 3的结果。如何从搜索get变量中转义/ 3?
这是我的控制器索引中的代码
$search = $this->input->get('search');
$search_ses=array('search_ses'=>$search);
$this->session->set_userdata($search_ses);
$data['item_details'] = $this->Model_items->search_item_details(3,$start,$search);
$config['first_url'] = 'Search/index/?search='.$search;
$config['base_url'] = base_url().'Search/?search='.$search;
$config['total_rows']= $this->Model_items->getSearch_count($search);
$config['per_page']=3;
$config['last_link'] = 'Last »';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next →';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '← Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$data['pages'] = $this->pagination->create_links();
我的模特
function search_item_details($num,$start,$search)
{
$offset = $this->uri->segment(3);
$query = $this->db->select('*')
->from('shop_items')
->like('shop_item_name',$search)
->where('shop_item_status',1)
->where('shop_item_stock_num >',0)
->order_by('shop_item_date_posted', 'DESC')
->order_by('shop_item_featured', 'DESC')
->limit($num,$offset)
->get();
return $query->result();
}
答案 0 :(得分:0)
假设
$search = $this->input->get('search');
//outputs 'nike/3'
你可以轻松地做这样的事情
$search = $this->input->get('search');
$get = explode('/',$search);
$search = $get[0];
//in this case 'nike'
如果你需要&#39; 3&#39;在耐克之后,你可以做到这一点
$number = $get[1];
您可以在PHP手册上查看explode