PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I want to sort the database search results in php or somethingelse. Basically, the results are returned on a php page and need to be sorted either by columns. I managed to display the results on the page with the code below and it works, but now i need to add the sorting bit, but i am stuck with it. I dont want to fetch the data from the database again but just to manipulate the existing entries. how can this be achieved in php?
When someone selects a different sort by, you just change the order by in the query.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
I think the original poster only wants to retrieve the data from the DB and be able to sort it after the 1 query is done. I've done this in the past when sorting can easily be done in Javascript without needing to bother the database again.
Doing the sorting in PHP without accessing the database again is a bit of a pain because you have to store the results either in $_SESSION or a form - plus you're bothering the web server again.
The best way to do this is use Javascript (unless you want this functionality available to the 12 people who don't have Javascript turned on). Specifically, I've used the tablesorter plugin & it works quite well.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Thats correct Pickle. I want to sort the results on the page that are already dislayed. You mentioned a plugin. is that easy to implement? do i have to install it on the web server? need to check with my host if the allow it?
Jonah: you mentioned In Javascript, you could do something cool, like clicking on the column title to sort by that column (click again to reverse order). do you any examples that are similar to my case i can look at?
It still not working. Ity gives error message: 'undefined is null or nit an object'
The example does not show how to combine paging with sorting? which documentation you are referring to?
Can you clarify what you pt in the header?
this is what I have:
<script type="text/javascript" src="js/jquery-1.4.2.min.js"> </script>
<script type="text/javascript" src="js/jquery.tablesorter.pager.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.min.js"></script>
Ok managed to get it tweaked, but noted that the max page number is only applied once the page is refreshed. the first time the page is rendered, it displays all records in the database e.g. 40 records, then the user will have to use the page size option to limit the number of records. is it possible to apply the limit when the page is rendered first time and then use the page option to show the other records?
I may have 200 records in the database and dont want to display them all in the first place.