Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6773145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:37:57+00:00 2026-05-26T15:37:57+00:00

I am having difficulties implementing the codeigniter pagination class. I have created my model,

  • 0

I am having difficulties implementing the codeigniter pagination class. I have created my model, view and controller for getting my news articles and data is echoed in the view successfully.

My problem is that when I attempt to implement pagination it seems like I am unable to get the correct count of fields in my database. Can somebody show me what I have done wrong?

The pagination links display perfectly, but the content echoed does not appear to be limited. How can I count the rows of the query?

Required classes for the pagination are autoloaded

Model:

class News_model extends CI_model {


    function get_allNews()
    {
        $query = $this->db->get('news');

                    foreach ($query->result() as $row) {
        $data[] = array(
             'category' => $row->category,
            'title' => strip_tags($row->title),
            'intro' => strip_tags($row->intro),
            'content' => truncate(strip_tags( $row->content),200),
              'tags' => $row->tags

        );
    }

    return $data;
    } 

Controller

      // load pagination class
    $config['base_url'] = base_url().'/news/index/';
    $config['total_rows'] = $this->db->get('news')->num_rows();
    $config['per_page'] = '5';
  $config['full_tag_open'] = '<div id="pagination">';
            $config['full_tag_close'] = '</div>';

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

$viewdata['allnews'] = $this->News_model->get_allNews($config['per_page'],$this->uri->segment(3));

View

  <?php if (isset($allnews)): foreach ($allnews as $an): ?>
               <?php echo heading($an['title'], 2); ?>
                <?php echo $an['content']; ?>
            <?php endforeach;
        else: ?>
            <h2>Unable to load data.</h2>
        <?php endif; ?>
            <?php echo $this->pagination->create_links(); ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:37:58+00:00Added an answer on May 26, 2026 at 3:37 pm

    In your controller, you’re passing parameters to your get_allNews method, but your method doesn’t make use of those parameters:

    $viewdata['allnews'] = $this->News_model->get_allNews($config['per_page'],$this->uri->segment(3));
    

    So you are getting all records, and expecting the limited result set. You need to change the beginning of your get_allNews method like this:

    class News_model extends CI_model {
    
    // make use of the parameters (with defaults)
    function get_allNews($limit = 10, $offset = 0) 
    {
        // add the limit method in the chain with the given parameters
        $query = $this->db->limit($limit, $offset)->get('news'); 
        // ... rest of method below
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having difficulties implementing custom widget rendering in a QListView . I currently have
I am having difficulties getting a span tag to work properly inside a table.
I'm having difficulties getting XslCompiledTransform.Load method to take a server path. I googled around
I am having difficulties how to construct my question, but if I have to
I'm having difficulties displaying data in a UITextView in iPhone programming. I'm analyzing incoming
I am having difficulties with a program that I have been working on all
I am having difficulties with pages that have more than one <audio> when I
I am having difficulties implementing a custom ASP.NET RoleProvider. First off, let me show
I'm implementing a small game and am having trouble getting the physics working properly.
I am having difficulties testing Controllers in Codeigniter: I use Toast but when I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.