natrone Posted December 27, 2003 Share Posted December 27, 2003 Hello, I\'m a noob in need of some help. I currently have a page displaying all contents of a mysql table. There are 5 fields in the table. Name, Games Played, Points, Interceptions and Sacks. Works great. I want to create a drop down menu with options- name, points, interceptions and sacks. And when the option is selected from the menu, then the data is listed by that option is descending order. I\'m assuming I use the get function but not sure. Currently the table displays by name in descending order, but I want for example, if you select points from the menu, that the table is requeried to list the data by points in descending order and so on. Hope this makes sense. Any advise is appreciated. Please make it easy to understand. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/1562-noob-in-need-of-some-help/ Share on other sites More sharing options...
Barand Posted December 28, 2003 Share Posted December 28, 2003 Add a form with the dropdown in it. <form name="form1" method="get" action="<?=$_SERVER[PHP_SELF]?>" > <SELECT name="orderby"> <OPTION Value="Name">Name</OPTION> <OPTION Value="Games Played">Games Played</OPTION> <OPTION Value="Points">Points</OPTION> <OPTION Value="Interceptions ">Interceptions </OPTION> <OPTION Value="Sacks">Sacks</OPTION> </SELECT> <INPUT type="submit" value="Sort"> </form> Get the selected value, defaulting to name if no selection [php:1:2ea7f60812]<?php $orderby = isset($_GET[\'orderby\']) ? $_GET[\'orderby\'] : \'Name\' ; ?>[/php:1:2ea7f60812] Set up your query [php:1:2ea7f60812]<?php $query = \"SELECT Name, `Games Played`, Points, Interceptions , Sacks FROM tablename ORDER BY `$orderby` DESC \"; ?>[/php:1:2ea7f60812] Process results as now. hth Quote Link to comment https://forums.phpfreaks.com/topic/1562-noob-in-need-of-some-help/#findComment-5130 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.