CodeIgniter Forums
{Solved} Pagination problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: {Solved} Pagination problem (/thread-9821.html)



{Solved} Pagination problem - El Forum - 07-09-2008

[eluser]markanderson993[/eluser]
Scroll Down Please


{Solved} Pagination problem - El Forum - 07-11-2008

[eluser]markanderson993[/eluser]
I kept working on the problem, so this comment is now useless, scroll down! (last time I promise)


{Solved} Pagination problem - El Forum - 07-11-2008

[eluser]markanderson993[/eluser]
PLEASE HELP! I will be forever grateful to anyone who has the solution!

Alright it seems I'm shooting in the dark on this one. However for those of you who are actually reading this, I have revised my pagination and now it semi-works. The only problem now is that the pagination works but... backwards. What I mean is, it begins selected on the last page (the number bolded of course). When you click a number lower than the one selected you are get the appropriate results (backwards of course) and the last number remains bolded and still selected.

Example:

Result 6
Result 7

<< 1 2 3

Now I click link 2, I get

Result 5
Result 4

<< 1 2 3 (notice: 3 is still selected)

Here is my code. My Controller function:

Code:
function viewforum()
    {    
        $this->load->library('pagination');
        
        $config['base_url'] = base_url().'forums/viewforum/'.$this->uri->segment(3).'/page/';
    
        $this->db->where('forum_id',$this->uri->segment(3));
        $get_results = $this->db->get('sb_topics');
        $count_results = $get_results->num_rows();
    
        $config['total_rows'] = $count_results;
        $config['per_page'] = 2;
        
        $this->db->where('forum_id',$this->uri->segment(3));
        $this->db->order_by('topic_time', 'DESC');
        $data['results'] = $this->db->get('sb_topics',$config['per_page'],$this->uri->segment(5));
        
        $this->pagination->initialize($config);
        
        
        
        $this->template->load('forums/viewforum_view',$data);
    }

My viewforum_view

Code:
&lt;?php // Security

    $this->db->where('forum_id',$this->uri->segment(3));
    $query = $this->db->get('sb_forums');
    if (!$query->num_rows() > 0 ) redirect('forums');

?&gt;

<div class="forums">

    &lt;?php $this->load->view('forums/forum_header'); ?&gt;
    
     <table class="forum_topics" width="100%" style="border:1px solid #EEE;line-height:15px;" cellspacing="0">
    
     <tr>
         <td style="color:#fff;background-color:#FF6633;border-bottom:2px solid #999;font-size:12px;width:170px;padding-left:20px;"><b>Topics</b></td>
        <td style="color:#fff;background-color:#FF6633;border-bottom:2px solid #999;font-size:12px;width:50px"><b>Author</b></td>
        <td style="color:#fff;background-color:#FF6633;border-bottom:2px solid #999;font-size:12px;width:40px;text-align:center"><b>Replies</b></td>
        <td style="color:#fff;background-color:#FF6633;border-bottom:2px solid #999;font-size:12px;width:40px;text-align:center"><b>Views</b></td>
        <td style="color:#fff;background-color:#FF6633;border-bottom:2px solid #999;font-size:12px;width:100px"><b>Date Posted</b></td>
     </tr>
    
     &lt;?php foreach($results->result() as $row): ?&gt;
    &lt;?php
            $this->db->where('id',$row->poster_id);
            $query = $this->db->get('users');
            $users_row = $query->row();
    ?&gt;    
    <tr>
        <td style="border-top:1px solid #EEE;padding-left:20px;">
            <span style="font-size:12px;"><b><a >topic_id;?&gt;">&lt;?=$row->topic_title?&gt;</a></b></span><br />
            <span style="font-size:9px;">&lt;?=(ucfirst($users_row->username))?&gt;</span>
        </td>
        <td style="border-top:1px solid #EEE;">&lt;?=(ucfirst($users_row->username))?&gt;</td>
        <td style="border-top:1px solid #EEE;text-align:center;">&lt;?=$row->topic_replies?&gt;</td>
        <td style="border-top:1px solid #EEE;text-align:center;">&lt;?=$row->topic_views?&gt;</td>
        <td style="border-top:1px solid #EEE;">&lt;?=unix_to_human($row->topic_time)?&gt;</td>
    </tr>
    
    &lt;?php endforeach; ?&gt;
    
    </table>
    
    <div style="border:1px solid #CCC;margin-top:10px;background-color:#fff"><div style="border:1px solid #EEE;padding:5px">
        &lt;?php echo $this->pagination->create_links(); ?&gt;
    </div></div>

</div>



{Solved} Pagination problem - El Forum - 07-11-2008

[eluser]markanderson993[/eluser]
Well I finally found that I needed an extra line of code in my controller: $config['uri_segment'] = '5';
I hope this helps out anybody else with the same problem I had.
Smile


{Solved} Pagination problem - El Forum - 07-12-2008

[eluser]Jesse2303[/eluser]
Thanks now I can use my pagination good (y)