Re: Sort table by column and pagination

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We have quite a complex product all written in PHP and our own mySQL
wrapper. We initially wanted to use smarty, but due to time constraints, we
couldn't re-write everything, so it never got implemented.

Two feature requests we get a lot are the ability to sort the tabular data
by column heading (click once for ascending and again for descending) and
the second is pagination.

My guess is finding code that does this that you can integrate is going to take longer than just doing it yourself. It's not that bad...

Just add some variables that either get kept in a session or passed around via URL's to store the $offset and $order_by.

Then in your code set your $limit.

Then it's just a matter of adjusting your SQL to add "ORDER BY $order_by LIMIT $limit OFFSET $offset" when relevant. For your array, it's the same thing, but use array_slice.

To go to the next page just have the link set $offset to $offset + $limit. Similarly for previous.

Then add the boundary checks, etc.

Good luck!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux