0

controllers/home.php

$this->page_model->counter($this->data['post_detail']->post_ID);
        $this->data['post_list'] = $this->post_model->post($this->data['post_detail']->post_ID);
        $this->data['gallery_list'] = $this->post_model->post($this->data['post_detail']->post_ID, true);       

        $isAjax = array('news-post');
        if (in_array($this->data['post_detail']->template_name, $isAjax))
        {
            if ( ! $this->input->is_ajax_request())
                redirect($this->data['page_detail']->post_alias);

            return $this->load->view($this->data['post_detail']->template_name, $this->data);
        }
        $this->load->view($this->data['post_detail']->template_name, $this->data);

views/news.php

<?php 
        $this->load->library('pagination');

        $config['base_url'] = 'http://gsa-constructionspecialist.com/articles/article';
        $config['total_rows'] = 14;
        $config['per_page'] = 5;

        $this->pagination->initialize($config);

        ?>

    <div class="w626 content right">
        <?php
        if ($post_list){
        foreach ($post_list as $pl){
        ?>
        <div>
            <p><br><br><strong><?php echo $pl->post_title; ?></strong></p>
            <p><?php echo date('F jS, Y',strtotime($pl->post_date)); ?></p>
            <br/>
            <div style="text-align:justify"><?php echo word_limiter(strip_tags($pl->post_content),25); ?><a href="<?php echo site_url('articles/'.$this->uri->segment(2).'/detail/'.$pl->post_alias); ?>"><span style="color:#fff">&nbsp;&nbsp;Read More ></span></a></div>
        </div>
        <?php } } ?>

    <?php echo $this->pagination->create_links();   ?>

I am trying to set the pagination but it only appears on the bottom and it does not hide the articles that suppose to be on the next page.

Please help fix the codes? Thanks in advance.

2
Contributors
2
Replies
46
Views
10 Months
Discussion Span
Last Post by davy_yg
0

CodrIgniter's pagination library just builds the links you can use to navigate the page. You still need to feed the page number and rows per page into the method you use to do the actual database query and limit it from only retrieving the desired rows, based on the current page.

0

Here is an alternative. I am trying this paging simulation but I have not yet successful.

models/name_model.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Name_model extends CI_Model {

    public function __construct()
    {
        parent::__construct();
    }

    public function get_name($num, $offset)
    {
        $query = $this->db->get('name', $num, $offset);
        return $query->result();
    }

}

controllers/cwelcome.php

public function index($id=NULL)
    {
        $this->load->model('name_model');       

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

        $config['base_url'] = 'http://www.gsa-constructionspecialist.com/articles/article';
        $config['total_rows'] = 15;
        $config['per_page'] = 5;

        $this->pagination->initialize($config);

        $data['halaman'] = $this->pagination->create_links();

        $data['query'] = $this->name_model->get_name($config['per_page'], $id);

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

views/welcome_message.php

<body>

 <?php
 //kalo data tidak ada didatabase
 if(empty($query))
 {
 echo "<tr><td colspan=\"6\">Data tidak tersedia</td></tr>";
 }else
 {
 $no = 1;
 foreach($query as $row)
 {
 ?>
 <tr>
 <td><?php echo $row->name;?></td>
 </tr>
 <?php
 $no++;
 }}
 ?>
 </table>
 <div class="halaman">Halaman : <?php echo $halaman;?></div>

</body>

Here is the error messages:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Cwelcome::$db

Filename: core/Model.php

Line Number: 77

Backtrace:

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\Paging\application\models\name_model.php
Line: 13
Function: __get

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\Paging\application\controllers\Cwelcome.php
Line: 35
Function: get_name

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\Paging\index.php
Line: 315
Function: require_once

Fatal error: Call to a member function get() on a non-object in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\Paging\application\models\name_model.php on line 13
A PHP Error was encountered

Severity: Error

Message: Call to a member function get() on a non-object

Filename: models/name_model.php

Line Number: 13

Backtrace:

Line Number: 13

models/name_model.php

$query = $this->db->get('name', $num, $offset);

How to fix the error message?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.