Ell20 Posted December 8, 2007 Share Posted December 8, 2007 Hi, I currently have a fixtures table which displays all the fixtures automatically in ascending order for date when the page is loaded. This is exactly what I want to begin with but I would also like to add a filter (think this is right word?) so that the user could then order the results how they wish for example by Team Ascending or Date Descending or Venue Home. Appreciate any help on adding this to my page. Elliot Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 8, 2007 Share Posted December 8, 2007 <?php $filter = // filter goes here $order = // Filter order ascending or descending $query = mysql_fetch_array("SELECT * FROM table_1 ORDER BY $filter $border"); while($row=mysql_fetch_array($query)){ echo $row['item']; } ?> Explanation Well, the first couple of lines I use 2 variables, one called $filter, and the next $order. $filter could be anything, it can be a drop down menu saying - Filter by Teams - Filter by Date ...etc $order is the variable that which describes the order of the data shown, if he or she choses Filter by Teams Ascending, then it will show the teams from a -z, or if its a date, it will show from oldest to newest and vice versa. Quote Link to comment Share on other sites More sharing options...
Ell20 Posted December 8, 2007 Author Share Posted December 8, 2007 I kind of get what your saying but can the $filter and $order be drop down boxes that the user can select from? Thanks Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 8, 2007 Share Posted December 8, 2007 I kind of get what your saying but can the $filter and $order be drop down boxes that the user can select from? Thanks Yes, $filter and $order are suposed to be drop down menus $filter - Filter by Date - Filter by Teams $order - Ascending - Descending. Please read my post from above, i added an explanation. Your welcome btw. Quote Link to comment Share on other sites More sharing options...
Ell20 Posted December 8, 2007 Author Share Posted December 8, 2007 I think im nearly there but having a bit of trouble. I want to preset the table so that when you view the page it orders by date ASC, then when you use the filter it filters by what ever you wish but im not really sure how to do that. I have tried presetting the values like so: $filter = 'date'; $order = 'ASC'; Then if they filter: if (isset($_POST['submit6'])) { $order = $order; $filter = $filter; } The SQL here? Thanks Quote Link to comment Share on other sites More sharing options...
Ell20 Posted December 8, 2007 Author Share Posted December 8, 2007 Not to worry, solved my own error needed to add: $order = ($_POST['order']); Thanks for your help! Quote Link to comment Share on other sites More sharing options...
phpSensei Posted December 8, 2007 Share Posted December 8, 2007 Not to worry, solved my own error needed to add: $order = ($_POST['order']); Thanks for your help! lol, you got it wrong. $filter = $_POST['filter']; // list menu $order = $_POST['order']; // list menu 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.