Alexhoward Posted March 31, 2008 Share Posted March 31, 2008 Hi Everyone! I'm just looking for some advice before i start messing around with any code What i'd like is some sort by buttons e.g. - Name - Rating...etc But i'm not sure how to do this... what i'd really like it to do is something like: in the code: select * from 'where_ever' sort by $button then some kind of way to say that when a button is pressed it sets the variable Is that possible? Thanks in advance Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted March 31, 2008 Author Share Posted March 31, 2008 Can anyone point me in the right direction...? Thanks! Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted March 31, 2008 Share Posted March 31, 2008 you can try adding like a &sortby=name&sort=desc/asc then $sortby=$_GET['sortby']; $sort=$_GET['sort']; mysql_query("SELECT * FROM `table` SORT BY $sortby $sort"); think that should work Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted March 31, 2008 Author Share Posted March 31, 2008 Hi, Thanks for replying! and this would only sort if the button was pushed....? Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted March 31, 2008 Share Posted March 31, 2008 well you mean like button or link? if you make a link you can make it something like this <?php $sortby=$_GET['sortby']; $sort=$_GET['sort']; if (!$sortby) { $sortby="name"; } if (!$sort) { $sort="desc"; } if ($sort=="asc") { $ascdesc = "desc"; } elseif ($sort=="desc") { $ascdesc = "asc"; } echo '<a href="filename.php?sortby=name&sort='.$ascdesc.'"><br />"; $result=mysql_query("SELECT * FROM `table` SORT BY $sortby $sort"); // ... Follow up with the rest of the code here ... ?> hope this guides u a little further Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted March 31, 2008 Author Share Posted March 31, 2008 Thanks for your help! but i really mean a button.... i don' want to double the amount of pages by having the sort as a link I'd like to do it dynamically.. is it possible, or a just a real pain for minimal gain? Quote Link to comment Share on other sites More sharing options...
clown[NOR] Posted March 31, 2008 Share Posted March 31, 2008 you dont need to link to another page.. you can do everything inside the same file.. Quote Link to comment Share on other sites More sharing options...
Alexhoward Posted April 3, 2008 Author Share Posted April 3, 2008 Oh, ok so the buttons a form, and it says if the buttons pushed use this variable? Thanks for all your help. should have time to look at it tonight Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.