You know the order by clause of the select statement? Is it possible to set up a way where you could click on a link and pass .php?Sortby=ColumName and then setup the select to order by Sortby. I've been messing with that, but couldn't get it to work.
The best I can come up with is just using the same code over and over in php files with differant names to sort the table by differant categories. I know there has to be a way to do it the other way :/
When I tried it the other way, I have it setup like this:
<a href="www.server.com/file.php?sortby=Date">
"select ............... from Table order by sortby desc");
Anyone have the solution?
Passing data to the order by clause?
Moderator: General Moderators
Well, you could do drop box that contains the options
Then just send it to your page using form, js or whatever method that pleases you
then you just say
Or if you send via POST, then ofcourse $_POST['sort_by']....
Hope that helps..
-9902468
Code: Select all
print('<select name=''sort_by''>
<option value=''name''> Name </option>
<option value=''date''> Date </option></select');then you just say
Code: Select all
$query = 'select column1, column2, from some_table order by '.$_GETї'sort_by'].' desc';Or if you send via POST, then ofcourse $_POST['sort_by']....
Hope that helps..
-9902468
Don't forget to take into account the possibility that nothing could be selected, what do you do then?
There is also a post about injection attacks which might be an issue if you allow other parameters to be entered. Just so your aware.
See viewtopic.php?t=4814&highlight=injection+attack
There is also a post about injection attacks which might be an issue if you allow other parameters to be entered. Just so your aware.
See viewtopic.php?t=4814&highlight=injection+attack