Welcome Guest, Not a member yet? Register   Sign In
Pagination question
#1

[eluser]CIfan1000[/eluser]
Hi,

Althought the manual says the Pagination class is simple, I am embarrased to say I am not getting it. I will try and explain why and any help will be much appreciated.

I have the following in a view:

Code:
$this->db->like('CityTown', $SearchCityTown);
                $query = $this->db->get('listings');

                // Select all the records in the listings table that match the search criteria:
                //$query = $this->db->query("SELECT * FROM listings WHERE CityTown = '{$SearchCityTown}' ");

                echo $query->num_rows()." listings found."."</br></br>";

                foreach ($query->result() as $row)
                    {
                        // NOTE: Field names are case sensitive
                        echo "<hr />";
                        echo "<h3>".$row->Title."</h3>";
                        echo "Location: ".$row->CityTown;
                        echo "</br>";
                        //echo "Listing ID: ".$row->ListingID;
                        echo "</br>";

                        $EditURI = "listingview/index/".$row->ListingID."/";
                        echo anchor_popup($EditURI, 'View details');

                        echo "</br>";
                        echo "</br>";
                    }

The manual says, in describing the Pagination class:

"base_url This is the full URL to the controller class/function containing your pagination."

I don't understand how setting some Pagination config settings can affect my View code above.

It could of course be that the above code should somehow be in the controller, but then I do not know or see how to pass the query result info to the View....

The manual does not describe how to integrate the pagination class with query results.

Thanks in advance for any help!
#2

[eluser]Flemming[/eluser]
very quickly, I hope I can shed light on this for you ....

the pagination class needs to be fed information, eg. total number of results, number of results to show per page. it will then generate the pagination links that you can display in your view. These links (including the base_url() ) are used to send info to your controller, eg. /controller/method/startNumber

so you are then telling your controller to LIMIT the results it returns to the quantity you specify in the controller, and starting at row startNumber (/controller/method/startNumber)

hope this will help some too:
Code:
$start = (int) $this->uri->segment(3);
        ($start) ? $lower = $start : $lower = 0;

        
        $config['base_url'] = '/vacancies/view/';
        $config['uri_segment'] = 3;
        $config['total_rows'] = $this->vacancies_model->countAllVacancies();
        $config['per_page'] = 8;
        $config['num_links'] = 5;
        $config['full_tag_open'] = '<p class="pagination">';
        $config['full_tag_close'] = '</p>';
        
        $this->pagination->initialize($config);
        
        $data['pagination'] = $this->pagination->create_links();
        
        $data['vacancies'] = $this->vacancies_model->getPagedLiveVacancies($lower, $config['per_page']);

you can see that I'm getting results here:
Code:
$this->vacancies_model->getPagedLiveVacancies($lower, $config['per_page'])
so the query is being told the start number and the quantity of rows to return.

Sorry but I have to dash, I hope I havent confused you further and maybe you can make some sense of what I've written!
#3

[eluser]CIfan1000[/eluser]
Hi flemming,

Thank you very much for your quick response.

I will try and work thru what you have shared with me.

Good coding!
#4

[eluser]Thorpe Obazee[/eluser]
http://godbit.com/article/pagination-with-code-igniter

This is a good tutorial on the pagination class.
#5

[eluser]CIfan1000[/eluser]
Hi Chamyto!

That tutorial looks great.

I wont have a chance to try it for a few days but it looks very thorough and I dont think I will have any problems.

Thanks for taking the time to help me out.




Theme © iAndrew 2016 - Forum software by © MyBB