搜索查询分页上问题
在view中代码。<form action="<?=site_url('insertproduct/chaxun')?>" name="name" method="post">
<tr>
<td>名字查询</td>
<td><input type="text" name="pname" id="pname" /></td>
<td><input type="submit" name="csubmit" id="csubmit"value="查询相关名称" /></td>
</tr>
</form>
控制器里面
function chaxun($pname='',$offset=''){
if ($this->input->post('csubmit'))
{
$limit=2;
$this->load->model('Product_model');
$total=$this->Product_model->chaxun_count();
$pname = $this->input->post('pname');
if($pname=='') $pname = $this->input->get('pname');
$data['data']=$this->Product_model->chaxun_product($limit,$offset,$pname);
$config['base_url'] = base_url().'index.php/insertproduct/chaxun/'.$pname;
$config['uri_segment'] = 4;
$config['total_rows'] = $total;
$config['per_page'] = $limit;
$this->pagination->initialize($config);
$data['pag_links']= $this->pagination->create_links();
if ($data)
{
$this->load->view('listproduct',$data);
}
else
{
$dd ='没有查询到任何数据!';
$this->load->view('listproduct',$dd);
}
}
}
模型里面东西
function chaxun_count(){
$pname = $this->input->post('pname');
($pname) ? $this->db->where ('pname',$pname) : '';
return $this->db->count_all_results('inproduct');
}
function chaxun_product($limit,$offset,$pname=''){
$this->load->database();
($pname) ? $this->db->where ('pname',$pname) : '';
$this->db->limit($limit,$offset);
$query=$this->db->get('inproduct');
$ddd=$query->result() ;
return $ddd;
}
第一张页面能显示出来 问题是点击第二页时候 页面上什么都不显示。不知道 什么原因啊。忘知道告诉一声!谢谢啊! 第二页是用get访问的,没有用post表单,所以csubmit是空值
这句if($this->input->post('csubmit'))是假值,什么都不执行,当然是空白 回复 2# visvoy
那应该怎么判断,如何写呢?请详细请教! 保持搜索条件的分页查询 请用get方式,可以是传统的querystring也可以是CI的uri段方式,实在不行,你可以用session,cookies,总之post不可以,例子请到代码区下载一些代码看看就是了 ;P支持LS,那啥,php条件分页是常用算法了,是个网站都要这个代码,
不会的童鞋建议恶补,抱着一个现成的完整条件分页栗子啃十遍,英文囧的请用金山糍粑即时屈词 //分页显示
function index() {
$data['baseurl']=site_url();
if(!$this->session->userdata("admin"))
{
redirect("login.html");
}
$data["su_info"]=$this->phone_model->slect_phone_list();
$this->load->view('phone_list.html',$data);
}
//modle里面调用
//查询400类表页面内容
function slect_phone_list(){
$this->load->library('pagination');
$this->db->select('*');
$this->db->from('tel_status a ,supplier_info b');
$this->db->where('a.supplier_id = b.id');
$mycount = $this->db->count_all_results();
$config['base_url'] = site_url('phone_order/index');
$config['total_rows'] =$mycount;
$config['per_page'] = '2';
$config['num_links'] = '6';
$config['uri_segment'] = 3;
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$this->db->select('a.*,b.com_name');
$this->db->where('a.supplier_id = b.id');
$query=$this->db->get('tel_status a ,supplier_info b',$config['per_page'],$this->uri->segment(3));
if($query){
return $query->result();
}
else{
return NULL;
}
}
//查询内容分页
echo site_url("phone_order/phone_400_seach");
//第一次调用
function phone_400_seach(){
if (!$this->session->userdata("admin"))
{
redirect("login.html");
}
$sql=$this->input->post("keyname");
$data['baseurl']=site_url();
$data['su_info']=$this->phone_model->tel_status_seach($sql);
$this->load->view('phone_list.html',$data);
}
//model里面调用
//400电话状态表搜索内容 分页
function tel_status_seach($id)
{
$this->load->library('pagination');
$this->db->select('*');
$this->db->from('tel_status');
$this->db->like('soft_users',$id);
$mycount = $this->db->count_all_results();
$this->load->library('pagination');
$config['base_url'] = site_url('phone_order/phone_seach') . "/" . $id;
$config['total_rows'] = $mycount;
$config['per_page'] = '1';
$config['num_links'] = '6';
$config['uri_segment'] = 4;
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$this->db->select('*');
$this->db->like('soft_users',$id);
$query=$this->db->get('tel_status',$config['per_page'],$this->uri->segment(4));
if($query->result()){
return $query->result();
}else{
return null;
}
}
//第二次调用
function phone_seach($sql){
if(!$this->session->userdata("admin"))
{
redirect("login.html");
}
$data['baseurl']=site_url();
$data['su_info']=$this->phone_model->tel_status_seach($sql);
$this->load->view('phone_list.html',$data);
}
<TD colspan="7" vAlign=top ><?php echo $this->pagination->create_links();?></TD> ci分页下拉菜单
<?php
//view 视图
<div class="info_box" style="width:1100px;text-align:center;">查询:
<div class="detail_info"><br /><form name="search" id="search" method="POST" action="<?php echo $baseurl;?>admin/goods/searchclient/">
<label>
<select name="method" id="method">
<option value="0"> 按联系人 </option>
<option value="1"> 按公司名称 </option>
</select>
</label> 输入关键字: <input type="text" name="keyword" id="keyword"/> <input type="Submit" class="button" value="立即查询" onclick="return check()"/></form>
</div></div>
//controller
//控制器
function getlist()
{
$method=$this->input->post("method");
if($method==0) {
//按名称查询
$condition=$this->input->post("keyword");
$data['all_goods'] =$this->admin_model->post_a_goods($condition);
}
if($method==1) {
//按序号查询
$condition=$this->input->post("keyword");
$data['all_goods'] =$this->admin_model->post_b_goods($condition);
}
$data['baseurl']=site_url();
$this->load->view('admin/goods.html',$data);
}
//model
//获取查询新闻分页
function post_a_goods($id)
{
$this->db->like('name',$id);
$this->db->from('news');
$this->db->order_by('id','desc');
$mycount = $this->db->count_all_results();
$this->load->library('pagination');
$config['base_url'] = site_url('admin/goods/getlista') . "/" . $id;
$config['total_rows'] = $mycount;
$config['per_page'] = '10';
$config['num_links'] = '6';
$config['uri_segment'] = 5;
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$this->db->select('*');
$this->db->like('name',$id);
$this->db->order_by('id','desc');
$query=$this->db->get('news',$config['per_page'],$this->uri->segment(5));
return $query;
}
function post_b_goods($id)
{
$this->db->where('id',$id);
$this->db->from('news');
$this->db->order_by('id','desc');
$mycount = $this->db->count_all_results();
$this->load->library('pagination');
$config['base_url'] = site_url('admin/goods/getlistb') . "/" . $id;
$config['total_rows'] = $mycount;
$config['per_page'] = '10';
$config['num_links'] = '6';
$config['uri_segment'] = 5;
$config['full_tag_open'] = '<div class="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$this->db->select('*');
$this->db->where('id',$id);
$this->db->order_by('id','desc');
$query=$this->db->get('news',$config['per_page'],$this->uri->segment(5));
return $query;
}
//controller
//控制器
function getlista($sql)
{
$data['baseurl']=site_url();
$data['news'] = $this->News_model->post_a_goods($sql);
$this->load->view('admin/goods.html',$data);
}
function getlistb($sql)
{
$data['baseurl']=site_url();
$data['news'] = $this->News_model->post_b_goods($sql);
$this->load->view('admin/goods.html',$data);
}
?>
<TD colspan="7" vAlign=top ><?php echo $this->pagination->create_links();?></TD> 楼上的操作好麻烦啊。。。。
页:
[1]