[eluser]Unknown[/eluser]
I have read the user guide and a lot of posts with such a problem as mine on this forum but I don`t get a wright result. I have received no entries constantly from my database. Why does it happen? If i get nothing then i have a problem with my model, however, I check it very well. Try different database queries - also the same problem.
I try different other work pagination from other users but the same result. Maybe someone can help me to deal with this difficulty.
Controller
Code:
class Article extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Article_model');
}
public function listing($journal_id = '')
{
$journal_id = (int) $journal_id;
$per_page = 5;
$total = $this->Article_model->count_articles($journal_id);
$url = site_url('admin/article/listing/'.$journal_id.'/');
$this->load->library('pagination');
$config['base_url'] = $url;
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['uri_segment']= '5';
$data['articles'] = $this->Article_model->get_articles(journal_id,$per_page, $this->uri->segment(5));
$this->pagination->initialize($config);
$this->load->view('admin/article/list', $data);
Model
Code:
class Article_model extends CI_Model {
function count_articles($journal_id) {
$this->db->where('journal_id', $journal_id);
return $this->db->get('articles')->num_rows();
}
function get_articles($journal_id, $limit = NULL, $offset = NULL) {
$this->db->order_by('article_from_page');
$this->db->where('journal_id', $journal_id);
$this->db->limit($limit, $offset);
return $this->db->get('articles');
}
}
View
Code:
<?php if( ! is_null($articles)) : ?>
<?php foreach($articles->result() as $article) : ?>
<?php echo $article->article_authors; ?>
<?php echo $article->article_from_page.'-'.$article->article_to_page; ?>
<?php endforeach; ?>
<?php else : ?>
<p>There are no articles in this journal yet.</p>
<?php endif; ?>
<?php echo $this->pagination->create_links(); ?>