Dynamic Table Sorting - Help!!!
Posted: Thu Aug 27, 2009 12:15 pm
Hi guys,
I have been learning php for some few weeks now and I must say I am getting better. At the moment, I am building an application which queries a database based on the values filled on a form and displays the result on another page when the user clicks the submit button.
The results are displayed in a tabular form with Column headings which works fine. Here is my problem - I want to give users the ability to sort the results based on the column headings. For example, when he clicks on the 'Name' column, the results should be sorted alphabetically.
I came up with the idea of redirecting the page to itself (i.e. the results page) and running an sql statement basing the ORDER BY on the column selected by the user. Obviously, what I didn't realise was that the values passed to the results page from the form using POST would have been lost, so I keep getting errors complaining about those values. I tried to create hidden fields and hide these values into them but it doesn't seem to work. I did a bit of research and I discovered php Sessions.
My question is - do you think I should use sessions to achieve this or is there a better way? Any information would be greatly appreciated.
Thanks.
I have been learning php for some few weeks now and I must say I am getting better. At the moment, I am building an application which queries a database based on the values filled on a form and displays the result on another page when the user clicks the submit button.
The results are displayed in a tabular form with Column headings which works fine. Here is my problem - I want to give users the ability to sort the results based on the column headings. For example, when he clicks on the 'Name' column, the results should be sorted alphabetically.
I came up with the idea of redirecting the page to itself (i.e. the results page) and running an sql statement basing the ORDER BY on the column selected by the user. Obviously, what I didn't realise was that the values passed to the results page from the form using POST would have been lost, so I keep getting errors complaining about those values. I tried to create hidden fields and hide these values into them but it doesn't seem to work. I did a bit of research and I discovered php Sessions.
My question is - do you think I should use sessions to achieve this or is there a better way? Any information would be greatly appreciated.
Thanks.