Welcome Guest, Not a member yet? Register   Sign In
it is not paginating me, humm, dunno why :(
#4

[eluser]Josh Holloway[/eluser]
Firstly, I'd stop what you're doing and setup the following:

a model:
Code:
class Posts_model extends Model {

function Posts_model()
{
  parent::Model();
}

function get_posts($limit = NULL, $offset = NULL)
{
  $this->db->limit($limit, $offset);
  return $this->db->get('posts');
}

function count_posts()
{
  return $this->db->count_all_results('posts');
}
}

a controller:
Code:
class Posts extends Controller {

function Posts()
{
  parent::Controller();
}

function all_posts()
{
   $this->load->model('posts_model');
   $this->load->library('pagination');

   $per_page = 5;
   $total = $this->Posts_model->count_posts();
   $url = site_url('posts/all_posts');

   $config['base_url'] = $url;
   $config['total_rows'] = $total;
   $config['per_page'] = $per_page;
   $config['uri_segment'] = '3';

   $data['posts'] = $this->Posts_model->get_posts($per_page, $this->uri->segment(3));

   $this->pagination->initialize($config);
   $this->load->view('posts/all_posts', $data);
}
}

a view:
Code:
foreach ($posts->results() as $post):
    echo $post->title, '<br />';
    echo $post->content;
endforeach;

&lt;?php echo $this->pagination->create_links(); ?&gt;

I'll even give you the SQL script to get this working Smile
Code:
CREATE TABLE IF NOT EXISTS `posts` (
  `post_id` int(11) NOT NULL auto_increment,
  `title` varchar(100) NOT NULL,
  `content` text NOT NULL,
  PRIMARY KEY  (`post_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Right, once done, add a few records to the table posts and see if pagination is working.

If so, you can start to substitute bits out to get it working as required.


Messages In This Thread
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 05:35 AM
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 06:08 AM
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 06:26 AM
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 10:19 AM
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 12:58 PM
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 01:14 PM
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 01:25 PM
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 01:46 PM
it is not paginating me, humm, dunno why :( - by El Forum - 01-11-2011, 02:19 PM
it is not paginating me, humm, dunno why :( - by El Forum - 01-12-2011, 10:39 AM
it is not paginating me, humm, dunno why :( - by El Forum - 01-22-2011, 03:39 PM
it is not paginating me, humm, dunno why :( - by El Forum - 01-23-2011, 05:04 AM
it is not paginating me, humm, dunno why :( - by El Forum - 01-30-2011, 04:20 PM
it is not paginating me, humm, dunno why :( - by El Forum - 01-30-2011, 06:58 PM
it is not paginating me, humm, dunno why :( - by El Forum - 01-31-2011, 12:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB