1
votes

I am trying to create a pagination with just next and previous links instead of 1,2,3..etc.

So I have say item 1,2,3,4,5 in the database and each item is on one page.

If I am on item 2 page I would like a previous link for item 1 page and a next link for item 3 page...etc

So far I got up to retrieving all the items in the database and created a loop to spit out all the URL in each item. But I don't quite know the best way to strip off all the items except the adjacent items. This is the loop I have so far.

foreach ($item_url as $url) : echo $url['url']; endforeach;

This spits out all URL...But how do i proceed to list only the adjacent items and not count the current item I am on...I tried using next($url); to move the pointer if it matches the current item but it didn't work...

Thanks, guys!

1

1 Answers

1
votes

Here's a neat resource for paging tabular data without the headache of writing your own code or the need for any PHP at all. Throw all the results into a table (or output them via JSON if you are so inclined) Now, apply the DataTables plugin to the table id and tell it to do pagination. Voila, instant pagination, no brain damage required.