douceng7070
douceng7070
2015-05-15 01:43
浏览 58
已采纳

无法使用codeigniter分页类正确加载数据库结果

I don't know what i'm doing wrong here, can somebody please help, here's my controller.. I just want to display the database result according to the pagination set.

function post_paginates($offset = 0){
    $this->load->model('Users_model');
    $this->load->library('pagination');

    $limit = 3;
    $config['base_url'] = 'http://localhost/blog_ext/index.php/welcome/post_paginates/';
    $config['total_rows'] = $this->Users_model->totalcountPost();
    $config['per_page'] = $limit;
    $config['num_links'] = 2;
    $config['uri_segment'] = 4;
    $config['page_query_string']=true; 
    $config['query_string_segment'] = 'pageno';

    $this->pagination->initialize($config);
    $data['offset'] = $offset;

    $posts = $this->Users_model->get_post($limit, $offset);

    $data = array(
        'posts' => $posts,
        'pages' => $this->pagination->create_links()
    );

    $this->load->view('post_paginates', $data);
}

and here's my model

function get_post($limit, $offset){
    $query = $this->db->get('NEWS', $limit, $offset);
    return $query->result();
}

and here's the view

<div id="posts">
    <?php 
    if(isset($posts)){
        foreach ($posts as $titles) {
            echo $titles->HEADLINE;
            echo "<br>";
        }
    }
    ?>
</div>
<div id="pages">
    <?php echo $pages;?>
</div>

thanks in advance.. :-)

图片转代码服务由CSDN问答提供 功能建议

我不知道我在这里做错了什么,请有人帮忙,这是我的控制器..我 只想根据分页集显示数据库结果。

  function post_paginates($ offset = 0){
 $ this-&gt; load-&gt; model('  Users_model'); 
 $ this-&gt; load-&gt; library('pagination'); 
 
 $ limit = 3; 
 $ config ['base_url'] ='http:// localhost / blog_ext /  index.php / welcome / post_paginates /'; 
 $ config ['total_rows'] = $ this-&gt; Users_model-&gt; totalcountPost(); 
 $ config ['per_page'] = $ limit; 
 $ config  ['num_links'] = 2; 
 $ config ['uri_segment'] = 4; 
 $ config ['page_query_string'] = true;  
 $ config ['query_string_segment'] ='pageno'; 
 
 $ this-&gt; pagination-&gt; initialize($ config); 
 $ data ['offset'] = $ offset; 
 
  $ posts = $ this-&gt; Users_model-&gt; get_post($ limit,$ offset); 
 
 $ data = array(
'posts'=&gt; $ posts,
'pages'=&gt; $  this-&gt; pagination-&gt; create_links()
); 
 
 $ this-&gt; load-&gt; view('post_paginates',$ data); 
} 
   
 
 

这是我的模型

  function get_post($ limit,$ offset){
 $ query = $ this-&gt; db-&gt;  get('NEWS',$ limit,$ offset); 
返回$ query-&gt; result(); 
} 
   
 
 

这里是视图< / p>

 &lt; div id =“posts”&gt; 
&lt;?php 
 if(isset($ posts)){
 foreach($ posts as title)  {
 echo $ titles-&gt; HEADLINE; 
 echo“&lt; br&gt;”; 
} 
} 
?&gt; 
&lt; / div&gt; 
&lt; div id =“pages”&gt; \  n&lt;?php echo $ pages;?&gt; 
&lt; / div&gt; 
   
 
 

提前感谢..: - ) < / DIV>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dtufl26404
    dtufl26404 2015-05-15 02:38
    已采纳

    Use

    $offset = $this->input->get('pageno'); 
    

    for your offset.

    点赞 评论

相关推荐