katie77 Posted November 26, 2007 Share Posted November 26, 2007 Hi there, I have a dropdown menu which is supposed to filter a table to show results for professionals, students or all. But I don't really know what I'm doing. This is what I have so far. if (isset($_GET['occupation'])) { if ($_GET['occupation'] == "all") { $filter = $_GET['occupation']; } else { $filter = "'Student' or occupation = 'professional'"; } } else { $filter = "'Student' or occupation = 'professional'"; } //query table $result = mysql_query ("select * from software WHERE occupation = '$filter' ORDER by id DESC "); //drop-down menu echo " <form method='get' enctype='text/plain'> <select size='1' name='occupation'> <option value='All'>All</a></option> <option value='Student'>Students</a></option> <option value='Professional'>Professional</option> </select> <input type='submit' name='submit' value='Filter'> </form>"; Initially, I was able to filter for students or professionals, but since trying to have an all option (students and professionals) it has gone to pot, and I keep getting errors. I know that my quotation marks are not right, but I can't think of a solution. I would be more than happy to see any ideas, even if they are completely different to mine! Can anyone help me out? Many thanks, Katie Quote Link to comment https://forums.phpfreaks.com/topic/78995-solved-clever-way-to-make-a-dropdown-menu-filter/ Share on other sites More sharing options...
Barand Posted November 26, 2007 Share Posted November 26, 2007 if it's "All", omit the WHERE <?php if (isset($_GET['occupation'])) { if ($_GET['occupation'] == "All") { $filter = ""; } else { $filter = "WHERE occupation = {$_GET['occupation']}"; } } else { $filter = ""; } //query table $result = mysql_query ("select * from software $filter ORDER by id DESC "); //drop-down menu echo " <form method='get' enctype='text/plain'> <select size='1' name='occupation'> <option value='All'>All</a></option> <option value='Student'>Students</a></option> <option value='Professional'>Professional</option> </select> <input type='submit' name='submit' value='Filter'> </form>"; Quote Link to comment https://forums.phpfreaks.com/topic/78995-solved-clever-way-to-make-a-dropdown-menu-filter/#findComment-399767 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.