1
public function viewconsultant($id1='')
{

    $id1 = $id1 ? $id1 : 1;
    $pagenum=5;
    $start=($id1-1)*$pagenum;
    $users = $this->db->get_where('connections', array('user_id'=>97));
    $pageall = count($users);
    $config['total_rows']=$pageall;
    $config['per_page']=$pagenum;

    $config['num_links']=4;
    $config['base_url']="localhost/~chrisfu/linkedin2/index.php/connections/viewconsultant";
    $config['use_page_numbers']=true;

    $this->load->library('pagination');
    $this->pagination->initialize($config);
    $query = $this->db->get_where('connections', array('user_id'=>97), $pagenum, $start);
    $data['connections'] = $query->result();
    $this->load->view('profile_view',$data);
}

create_links()效果不好,它只显示一个空白字符串。我试过这个localhost/~chrisfu/linkedin2/index.php/connections/viewconsultant/2,它可以跳转到第二页,但不能创建分页链接。请帮忙!!

4

2 回答 2

3

问题是您没有创建链接..

$this->load->library('pagination');
$this->pagination->initialize($config);

// add the line below to your code
$data['links'] = $this->pagination->create_links();
// debug
// echo $data['links'];

$query = $this->db->get_where('connections', array('user_id'=>97), $pagenum, $start);
$data['connections'] = $query->result();
$this->load->view('profile_view',$data);

此外,您可以通过执行以下操作省略方法中的第一行:

public function viewconsultant($id1=1)
{

    // line below no longer necessary
    //$id1 = $id1 ? $id1 : 1;
}
于 2013-07-23T14:25:04.773 回答
1

试试这个:

function viewconsultant($id1=1, $offset = 0){
    $this->load->library('pagination');
    $pagenum=5;
    //$users  = $this->db->where('connections', array('user_id'=>97))->limit('20', $offset);
    $total      = $this->db->where('connections', array('user_id'=>97));
    $pageall    = $total->num_rows();
    //$users = $this->db->get_where('connections', array('user_id'=>97));
    //$start=($id1-1)*$pagenum;
    //$pageall = count($users);
    $config['total_rows']       = $pageall;
    $config['per_page']         = $pagenum;
    $config["uri_segment"]      = 3;
    $config['num_links']        = 4;
    $config['base_url']         = base_url()."/index.php/connections/viewconsultant/";
    $config['use_page_numbers'] = true;
    $this->load->library('pagination');
    $this->pagination->initialize($config);
    $query = $this->db->get_where('connections', array('user_id'=>97), $pagenum, $this->uri->segment(3));
    $data['connections'] = $query->result();
    $data['links']  = $this->pagination->create_links();
    $this->load->view('profile_view',$data);
}

现在,只需$links在您的视图文件中回显以获取分页。

于 2013-07-23T14:29:29.467 回答