|
控制器
function index()
{
$this->load->library("session");
@$data[uid] = $this->session->userdata('uid');
$this->load->model('testm');
$this->load->library('pagination');
$this->load->library('table');
$fkeyword=trim($this->input->get('keyword', TRUE));
$config['base_url'] = 'http://localhost/CodeIgniter_2.1.4/index.php/home/index?keyword='.$fkeyword.'';
//$config['base_url'] = 'http://localhost/CodeIgniter_2.1.4/index.php/home/index/'.$fkeyword.'';
$config['total_rows'] = $this->testm->user_select_count($fkeyword);
$config['per_page'] = 2;
$config['first_link'] = '第一页';
$config['last_link'] = '最后一页';
$config['prev_link'] = '上一页';
$config['next_link'] = '下一页';
$config['num_links'] = 4;
$config['page_query_string'] = TRUE;
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$this->pagination->initialize($config);
//$this->table->set_heading('ID', 'Title', 'Author', 'Description'); //利用表格类,可以生成头部
$data['results'] = $this->testm->user_selectall($page,$config['per_page'],$fkeyword);
$this->load->view("home",$data);
}
model中的
//计算总数
function user_select_count($fkeyword)
{
$this->db->count_all_results();
$this->db->like('uname',$fkeyword);
$query = $this->db->get('user');
return $query->num_rows();
}
//查询多个
function user_selectall($segment,$per_page,$fkeyword)
{
//$sql='select * from user where uname like '%xiaoqing%' limit '.$segment.','.$per_page;
//$query=$this->db->query($sql);
//return $query->result_array();
$this->db->like('uname',$fkeyword);
$this->db->select("*");
$query=$this->db->get("user",$per_page,$segment);
echo "$fkeyword"."<br/>";
print_r($query->result_array());
return $query->result_array();
}
谁能告诉我为什么啊。 |
|