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 Link to comment https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/ 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! Link to comment https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/#findComment-505621 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 Link to comment https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/#findComment-505625 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....? Link to comment https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/#findComment-505629 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 Link to comment https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/#findComment-505632 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? Link to comment https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/#findComment-505634 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.. Link to comment https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/#findComment-505645 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 Link to comment https://forums.phpfreaks.com/topic/98805-how-to-add-a-sort-by-button/#findComment-508324 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.