Welcome Guest, Not a member yet? Register   Sign In
Multiple Pagination on the same page
#1

[eluser]visormatt[/eluser]
So I have a page in which I would like to use the pagination feature in 3 different areas on the same page each with slightly different settings. As of right now it is working but here is my problem

data_1 -> i would like to display 3 rows
data_2 -> display 5 rows

but when ever the number in the URL segment gets large enough (page 3 of column 1) the links on column two jumps over to page 2

I am setting the pagination config inside of the actual view which may have something to do with it...

You can view here @ http://dev.fillinourfuture.org/


CONTROLLER
Code:
function index()
        {
            $data['title'] = "Welcome Landing -> index()";
            
            $data['qVideos'] = $this->resources_model->resources_video();
            $data['qNews'] = $this->news_model->page_news_feed(0, 3);
            $data['qNewsFeed'] = $this->news_model->page_news_feed($this->uri->segment(3), 5);
            
            
            $this->load->view('user/Landing', $data);
            /**** DATA ****/$this->benchmark->mark('controller_end');
        }
        function Page_News() {
            // DATA MODELS
            $data['qVideos'] = $this->resources_model->resources_video();
            $data['qNews'] = $this->news_model->page_news_feed(0, 3);
            $data['qNewsFeed'] = $this->news_model->page_news_feed($this->uri->segment(3), 5);
    
            
            $data['title'] = "Welcome Landing -> index()";
            $data['heading'] = "Welcome Landing -> index()";
            $this->load->view('user/Landing', $data);
            /**** DATA ****/$this->benchmark->mark('controller_end');
        }
        function Page_Articles() {
            // DATA MODELS
            $data['qVideos'] = $this->resources_model->resources_video();
            $data['qNews'] = $this->news_model->page_news_feed($this->uri->segment(3), 3);
            $data['qNewsFeed'] = $this->news_model->page_news_feed(0, 5);


            $data['title'] = "Welcome Landing -> index()";
            $data['heading'] = "Welcome Landing -> index()";
            $this->load->view('user/Landing', $data);
            /**** DATA ****/$this->benchmark->mark('controller_end');
        }

MODEL
Code:
public function view_news_feed()
    {
        return $this->db->query("
            SELECT * FROM news
            ORDER BY news_id ASC
        ")->result();
    }

    public function page_news_feed($page, $limit) {
    
        $currentPage = $page * 1; // ENSURES at least a 0
        return $this->db->query("
            SELECT * FROM news
            LIMIT $limit OFFSET $currentPage")
        ->result();
        
    }
    public function page_news_articles($page, $limit) {
    
        $currentPage = $page * 1; // ENSURES at least a 0
        return $this->db->query("
            SELECT * FROM news
            LIMIT $limit OFFSET $currentPage")
        ->result();
        
    }    
    public function count_news_feed() {
        return $this->db->query("
            SELECT * FROM news")
        ->num_rows();
    }

VIEW
Code:
<?php foreach($qNews as $rNews): ?>
                <div class="repeater">
                    <h3>&lt;?php echo $rNews->news_title; ?&gt;</h3>
                    <a >news_thumb?&gt;" rel="shadowbox[news]"><img height="75" width="100" class="floatLeft padRight" alt="temp">news_thumb; ?&gt;" /></a>
                    <p>&lt;?php echo $rNews->news_summary; ?&gt;</p>
                    <div class="linkBlock"><a >news_id; ?&gt;" >Full Article</a></div>
                    <div class="cleaner 5"></div>
                </div>
            &lt;?php endforeach; ?&gt;
            &lt;?php
                $config1['base_url'] = "/landing/Page_Articles";
                $config1['uri_segment'] = 3;
                $config1['total_rows'] = $this->news_model->count_news_feed();
                $config1['per_page'] = 3;
                $this->pagination->initialize($config1);
                echo $this->pagination->create_links();
            ?&gt;

        <ol class="newsFeed">
            &lt;?php foreach($qNewsFeed as $rFeed): ?&gt;
            <li><div class="listImage"></div><span>&lt;?php echo $rFeed->news_summary; ?&gt;</span></li>
            &lt;?php endforeach; ?&gt;
        </ol>
            &lt;?php
                $config2['base_url'] = "/landing/Page_News";
                $config2['uri_segment'] = 3;
                $config2['total_rows'] = $this->news_model->count_news_feed();
                $config2['per_page'] = 5;
                $this->pagination->initialize($config2);
                echo $this->pagination->create_links();
            ?&gt;
#2

[eluser]Unknown[/eluser]
I am having this same problem and was wondering if anyone fixed it or if it is even possible to have multiple instants of pagination on the same page.
#3

[eluser]ommy[/eluser]
also having this issue Sad
#4

[eluser]ommy[/eluser]
stupid thing to say. *slaps myself on the hands for posting the previous reply*

Lets say you need more than one pagination on a page.
Dump the information create_links() gives you into a var you assign to your layout, this will allow you to create X pagination on one page.

The crappy part is figuring out a way to pass all the current page vars to your controller i think.

Hope this helps you guys

T
#5

[eluser]ommy[/eluser]
i passed along the page number of the other columns to make sure the uri didn't skip any segments. That seems to work up until now.
If i read your post correctly (which i didn't do yesterday) i should be expecting issues when my paging receives a little more content?

T
#6

[eluser]disco_d[/eluser]
Attachments seem to be broken and im working on the problem an external link would be much appreciated if at all possible
#7

[eluser]hnaoueik[/eluser]
Guys , could u please upload again the multipagination.zip for me . Please. Link dies ! Thanks in advance !
#8

[eluser]peroperje[/eluser]
This is not codeigniter way ... but why not

Code:
$this->load->library('pagination');

$config['base_url'] = 'http://example.com/index.php/test/page_1/';
$config['total_rows'] = 200;
$config['per_page'] = 20;

$pagination_1=new CI_Pagination();
$pagination_1->initialize($config);
$view_data['pagination_link_1']=$pagination_1->create_links();


$config_2['base_url'] = 'http://example.com/index.php/test/page_2/';
$config_2['total_rows'] = 220;
$config_2['per_page'] = 25;

$pagination_2=new CI_Pagination();
$pagination_2->initialize($config_2);
$view_data['pagination_link_2']=$pagination_2->create_links();

....etc....
#9

[eluser]Unknown[/eluser]
[quote author="simona" date="1324496348"]Found this thread while searching for exactly the same problem as the OP.

I need two paginations on a single page. My URL is of the form:

http://www.example.com/controller/method...t1/offset2

where offset1 is the offset of the first pagination and offset2 is the offset of the second pagination.

I thought I had managed to solve the problem only using the CodeIgniter pagination class by setting config['suffix'] and config['first_url'], but I think I found a bug.

I had controller code of the form:

Code:
public function method($offset1 = 0, $offset2 = 0) {

$this->load->library('pagination');
$this->load->helper('url');

...

//first pagination item
$config['base_url'] = base_url(). 'controller/method/';
$config['first_url'] = base_url(). 'controller/method/0'; //set this because codeigniter pagination class does not append segment to the first page link when offset=0...
$config['suffix'] = '/'. $offset2; //append this to all generated urls
$config['total_rows'] = $table1_count;
$config['per_page'] = $table1_per_page;
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$table1_pagination = $this->pagination->create_links();

//second pagination item
$config['base_url'] = base_url(). 'controller/method/'. $offset1;
$config['first_url'] = base_url(). 'controller/method/'. $offset1; //need to reset this to same as 'base_url' after setting in first pagination
$config['suffix'] = ''; //need to reset this after setting in first pagination
$config['total_rows'] = $table2_count;
$config['per_page'] = $table2_per_page;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$table2_pagination = $this->pagination->create_links();

but the codeigniter pagination class was not appending the suffix to the "First" link or the "Previous" link :-S

So I fixed it, see the attached file (just modified two lines of the codeigniter pagination class create_links() method). The code above works with the attached MyPagination library.

Hope this helps![/quote]

Can I have that Mypagination library? I don't see any attached library




Theme © iAndrew 2016 - Forum software by © MyBB