How do you make pagination with search, sort by, order by and limit work? |
[eluser]Warz[/eluser]
Hi, I'm basically just looking for some tips on how to deal with pagination, the best way to do it... Right now I got this URL: http://localhost/memberbase/index.php/admin/users/index This page is supposed to display a list of all users. I need the following: - Search for username ($_GET search) - Sort by ID, Username, Email, Country, etc. Both ASC and DESC - Option to change amount of users displayed per page This works fine: http://localhost/memberbase/index.php/ad...rs/index/2 I also added support for sort by and order by, which looks like this: http://localhost/memberbase/index.php/ad...rderby/asc http://localhost/memberbase/index.php/ad...derby/desc etc.. Now, is it so, that I really need to do this: http://localhost/memberbase/index.php/ad...earch/john to search for user john? Is it possible to just go http://localhost/memberbase/index.php/ad...earch/john and then later do the sort by, order by and limit? I know this is possible with $_GET however when turning that on I get Quote:An Error Was Encountered All this just seems rather confusing and not very user friendly? Then maybe there is something I didn't know? What is best practise? How do YOU deal with pagination? Thanks!
[eluser]Kinsbane[/eluser]
I would honestly set up a custom route in your config/routes.php file that sends certain kinds of search queries to certain kinds of controllers so you can control exactly how the data goes through your system. I don't have a searching method, but I did build a documents library for my company and this is how I handled all the different things (including pages, ASC/DESC, and sort by/order by. This is an example of my routes file: Code: $route['documents/case-studies'] = 'documents/casestudies/index/all/0/last_modified/DESC'; As far as pagination goes, I actually had to modify the stock Pagination library that came with CI in order to include how the user is sorting, and by what they are sorting. Sample function: Code: function browse($family, $offset, $sortby, $sorthow) Now, I understand this has nothing to do with searching - but I think you're on the right path and I hope what I've posted can give you some ideas or inspiration on where to go. I see you got the error regarding the disallowed characters - another option is to temporarily store the search term in a hash string and use that
[eluser]predat0r[/eluser]
Check this for pagination and sort: http://net.tutsplus.com/tutorials/php/co...ular-data/ and this for search: http://net.tutsplus.com/tutorials/php/co...strings-2/ |
Welcome Guest, Not a member yet? Register Sign In |