Welcome Guest, Not a member yet? Register   Sign In
One row pagination - best practice.
#1

[eluser]morph london[/eluser]
I am building a site with Codeigniter that needs to cycle through a set of pages using a next button. These will come from a SQL result set. E.g. I load a master detail page for one record then I click the next button and it loads a new page with the next row in that result. I was going to try and use the pagnation class but I don't think it is going to fit my needs.

Does anyone know a standard way of doing this. Off the top of my head I was going to load all the rows for everypage and then write code to choose the next link from that, but this seems a waste of system resources.

Any help would be much appreciated.

Thanks Alex
#2

[eluser]Nick Husher[/eluser]
Why does pagination not meet your needs? If your SQL records are inserted sequentially, or have some notion of what page they're supposed to be, you can use pagination. Your basic pseudocode would be:

1. Initialize Pagination (set total rows = to the total number of pages, set per-page = to 1)
2. Find out what page we're on
3. Formulate query:
3a. If inserted sequentially, do $this->db->get('sql_table',$current_page,1); (you should set an orderby first, though)
3b. If inserted with a page number column, do $this->db->getwhere('sql_table', array('page_number'=>$current_page));
4. Return results.

Note that you have to parse what $current_page will be based off of your calling url.
#3

[eluser]tonanbarbarian[/eluser]
You are asking more for a Record Pager rather than pagination I think

To implement this depends on how you determine what the next and previous record are. If they are just determined by the ID then you could just pass the id in the link to the next and previous and build your query to find the id greater or less than the passed id limit 1 so that it always finds the next record

i.e.
http://localhost/paging/index/2/next - would find ID > 2 limit 1
http://localhost/paging/index/2/prev - would find ID < 2 limit 1

You can do something similar if you have another field you want to sort the paging on but it does get a bit more complex
#4

[eluser]morph london[/eluser]
Thats just what I needed thank you. Really easy way around it, I was going to call the database everytime and create an array for the list and work it out that way.




Theme © iAndrew 2016 - Forum software by © MyBB