CodeIgniter Forums
Sorting Arrays - 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: Sorting Arrays (/thread-8295.html)



Sorting Arrays - El Forum - 05-13-2008

[eluser]cristian_c[/eluser]
I have an array of 1 to 100 records
Im trying to do pagination. How can I collect 5 records at a time.

exemple

< id => '0', name => 'Charlie1', last_name => 'Smith' >
< id => '1', name => 'Charlie2', last_name => 'Smith' >
< id => '2', name => 'Charlie3', last_name => 'Smith' >
< id => '3', name => 'Charlie4', last_name => 'Smith' >
< id => '4', name => 'Charlie5', last_name => 'Smith' >
< id => '5', name => 'Charlie6', last_name => 'Smith' >
< id => '6', name => 'Charlie7', last_name => 'Smith' >
< id => '7', name => 'Charlie8', last_name => 'Smith' >
< id => '8', name => 'Charlie9', last_name => 'Smith' >
< id => '9', name => 'Charlie10', last_name => 'Smith' >

so what I need is to collect the record based on my url http://www.mysite.com/page/5
so the result need to start a record 5 with a limit off 5 records


Sorting Arrays - El Forum - 05-13-2008

[eluser]mironcho[/eluser]
Try array_slice() function or directly use these records within this array. If you are getting these records from database, why not using db limit functionality?


Sorting Arrays - El Forum - 05-13-2008

[eluser]Jamie Rumbelow[/eluser]
Or a "for" loop! There are a few ways of achiving this.


Sorting Arrays - El Forum - 06-17-2008

[eluser]dtrenz[/eluser]
[quote author="Jemgames" date="1210725561"]There are a few ways of achiving this.[/quote]

understatement of the year.


Sorting Arrays - El Forum - 06-17-2008

[eluser]xwero[/eluser]
as mironcho pointed out it's the most efficient if you limit your query for pagination. Otherwise you could look at a javascript solution that creates pages but then you don't have the url to link to a certain page, or you have to use something like the history jQuery plugin.