hyeteck Posted March 5, 2007 Share Posted March 5, 2007 hey guys, i have this php code that has a drop down menu that sorts the products on a website by name and price. <br /><form method="POST" action=""> <?php if(@$_SESSION['sortby'] != '') $thesortorder=(int)$_SESSION['sortby']; if(@$_POST['sortby']!='') $thesortorder=(int)$_POST['sortby']; ?> <select name="sortby" size="1"> <option value="1"<?php if(@$thesortorder==1) print ' selected'?>>Sort by product name</option> <option value="3"<?php if(@$thesortorder==3) print ' selected'?>>Sort by product price (ascending)</option> <option value="4"<?php if(@$thesortorder==4) print ' selected'?>>Sort by product price (descending)</option> </select> <input type="submit" value="Go"> </form><br /> instead of a dropdown menu, i want it to look something like this, where Name, Price (ascending), and price(descending) are links. Sort By: Name | Price (ascending) | Price (descending) how can i do that? thanks Link to comment https://forums.phpfreaks.com/topic/41245-drop-down-menu-with-php/ Share on other sites More sharing options...
benjaminbeazy Posted March 5, 2007 Share Posted March 5, 2007 use $_get method instead of $_post <a href="script.php?thesortorder=1">Name</a> | <a href="script.php?thesortorder=3">Price (ASC)</a> | <a href="script.php?thesortorder=4">Price (DESC)</a> Link to comment https://forums.phpfreaks.com/topic/41245-drop-down-menu-with-php/#findComment-199823 Share on other sites More sharing options...
hyeteck Posted March 5, 2007 Author Share Posted March 5, 2007 is there a reason to use "get" instead of "post" ? Link to comment https://forums.phpfreaks.com/topic/41245-drop-down-menu-with-php/#findComment-200142 Share on other sites More sharing options...
boo_lolly Posted March 5, 2007 Share Posted March 5, 2007 is there a reason to use "get" instead of "post" ? you'd use the 'get' method because you will be using links. what you do, is in the a href="" you add some parameters for the sql query to order by. for instance in benjamin's post you'd use something like... <?php if($_GET['thesortorder'] == 1){ $order = "ASC"; } if($_GET['thesortorder'] == 4){ $oder = "DESC"; } if(!isset($_GET['thesortorder'])){ $order = "DESC"; } $sql = "SELECT * FROM your_table ORDER BY ". $order .""; ?> if you were to use the 'post' method, you wouldn't be able to use links. you'd have to use forms, which is too much of a hassle when 'get' works this easily. at least, that's what i think benjamin meant by his post. Link to comment https://forums.phpfreaks.com/topic/41245-drop-down-menu-with-php/#findComment-200186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.