Welcome Guest, Not a member yet? Register   Sign In
Sorting Arrays
#1

[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
#2

[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?
#3

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

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

understatement of the year.
#5

[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.




Theme © iAndrew 2016 - Forum software by © MyBB