Array Pagination - how to page data stored in an array (e.g. from a news feed) - array paging |
[eluser]Flemming[/eluser]
I needed to page an array of data that was returned from Elliot Haughin's CI port of SimplePie - http://www.haughin.com/code/simplepie/ Here's what I came up with. Simple really, just using PHP's array_slice function: Code: $rss_items = $this->simplepie->get_items(); //just for example - $rss_items is my array Then by the time the $data['rss_items'] arrives at my view it only contains the records that I want, so I can loop through it with a foreach: Code: foreach($rss_items as $item) I THINK I've explained that right but any questions just give me a shout. I know it's incredibly simple but I thought it was worth posting!
[eluser]Eric Barnes[/eluser]
I know it is old but thank you. This is just what I was looking for today.
[eluser]god_module[/eluser]
Thanks for sharing! I didn't think of array_slice...
[eluser]maria clara[/eluser]
@ flemming, its interesting..can you explain more about it??? maybe i could use it for alternative ways of making pagination. regards, kahtrina
[eluser]Flemming[/eluser]
@maria clara it's only useful for data that is stored in an array (such as rss feed) rather than coming from a database where you can use LIMIT to retrieve a specific set of results to correspond with your pagination. |
Welcome Guest, Not a member yet? Register Sign In |