• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pagination error in CI


I'm having an issue with pagination in that the links are not displayed. The problem occurred as soon as I added the $num and $offset vars into the model, I'm guessing that my syntax is incorrect and would appreciate it if someone glances their eye over it and can't point me in the right direction.

The model in question is:
Quote: function getAllMusic($num,$offset){
$this->db->select('ae_music.*, ae_genres.*, ae_users.*, ae_locations.*');
$this->db->from('ae_music', 'ae_genres', 'users');
$this->db->join('ae_users', 'ae_users.id = ae_music.user_id');
$this->db->join('ae_genres', 'ae_genres.genre_id = ae_music.genre_id');
$this->db->join('ae_locations', 'ae_locations.location_id = ae_music.location_id');
$this->db->order_by('music_id', 'DESC');
$q = $this->db->get();
if($q->num_rows() > 0) {
foreach($q->result() as $getAllMusicRow) {
$data[] = $getAllMusicRow;

return $data;
else {
return FALSE;

It works fine in displaying all records and the pagination links without this line:


What you need to show is your pagination code!


Ooops, sorry - was a long night.

Here's the controller

function index()

            $config['per_page'] = '2';
            $config['base_url'] = base_url().'index.php/music/';
            $config['full_tag_open'] = '<p>';
            $config['full_tag_close'] = '</p>';
            $getAllMusicRow = $this->data_model->getAllMusic($config['per_page'],$this->uri->segment(3));                            
            $getAllGenresRow = $this->data_model->getAllGenres();                
            $getAllLocationsRow = $this->data_model->getAllLocations();                            
            $getTopMusicRow = $this->data_model->getTopMusic();            
            $getLatestSixRow = $this->user_model->getLatestSix();            
            $totalRows = count($getAllMusicRow);                        
            $config['total_rows'] = $totalRows;                        

            $data['pagination'] = $this->pagination->create_links();
            $data['getAllMusicRow'] = $getAllMusicRow;                                        ;
            $this->template->write('pageTitle', 'Music');
            $this->template->write_view('leftContent', 'music/music_view', $data);
            $this->template->write_view('midContent', 'common/mid_column_one', $data);
            $this->template->write_view('rightContent', 'common/right_column_one', $data);

and here's the pertinent bit from the view:

&lt;? echo $pagination; ?&gt;
&lt;? if(is_array($getAllMusicRow)) : ?&gt;    
    &lt;? foreach($getAllMusicRow as $row) : ?&gt;                                    
        <div class="musicRow">
            <p class="music_name">"&lt;? echo $row->music_name ;?&gt;"</p>
            <p class="user_name">by &lt;? echo anchor ('people/profile/'.$row->user_name_url, $row->user_name, 'class="simple"') ?&gt;</p>
            <p class="location_name">from &lt;? echo anchor ('places/city/'.$row->location_url_name, $row->location_name, 'class="simple"') ?&gt;</p>
            <p class="genre_name">genre &lt;? echo anchor ('music/genre/'.$row->genre_url_name, $row->genre_name, 'class="simple"') ?&gt;</p>  
            <div class="play">play</div>
            <div class="info">&lt;? echo anchor ('music/track/'.$row->music_url_name.'/'.$row->music_id, 'details') ?&gt;</div>
    &lt;? endforeach; ?&gt;
&lt;? else : ?&gt;
    <h5>There should always be something here, but just in case...</h5>
&lt;? endif; ?&gt;


You need to add this for one:
$config['uri_segment'] = 3;


Thanks for the response.

I've added the config option in, but still have no joy in getting the links to display.

When the limit() line is moved from the model, the links reappear but then of course it's not limiting the results. Completely stumped.


Pagination with CodeIgniter


Just in case anyone stumbles across this - I was stupidly populating the per_page with a count from the query that was grabbing the data, instead of running a separate count_all query.

Thanks for the link InsiteFX.


Your very Welcome.

Pagination is a little confusing at first but once you get use to it no problem.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.