Andrew R Posted August 18, 2006 Share Posted August 18, 2006 HiI need some help on creating a drop down menu filter that will filter the page, (roster.php) by location and age. I know how to create a filter using a form that will show the results on a secondary page such as viewroster.php but what I really wanted is for the page to be filtered without having to create a secondary page such as viewroster.php. Thanks Quote Link to comment Share on other sites More sharing options...
craygo Posted August 18, 2006 Share Posted August 18, 2006 Not sure I get what you are saying. Can you tell me what the form will look like and what you want it to do.Ray Quote Link to comment Share on other sites More sharing options...
Andrew R Posted August 18, 2006 Author Share Posted August 18, 2006 Yes. Ok I have a page (roster.php) that displays a list of users. An SQL query pulls information such as name, id, location, age etc from the database and displays it on (roster.php). What I want to do is create a drop down menu filter that will filter the results on the page by location and age. For example when you select "Age" from the drop down menu it will filter the page so it displays the users in the database by age ascending on roster.php[code]<select name="select"> <option value="Age" selected>Age</option> <option value="Location">Location</option></select>[/code]Cheers Quote Link to comment Share on other sites More sharing options...
craygo Posted August 18, 2006 Share Posted August 18, 2006 OK I got yayou can do this and let them sort asc and desc also[code]<form name=form1 method=GET action="<?=$_SERVER['PHP_SELF']?>"> <select name="select"> <option value="Age" selected>Age</option> <option value="Location">Location</option></select> <select name="order"> <option value="ASC">ASC</option> <option value="DESC">DESC</option> </select><br /> <input type=submit value=Sort name=submit /></form><?if(isset($_GET['select']) && isset($_GET['order'])){$filter = $_GET['select'];$order = $_GET['order'];} else {$filter = "id";$order = "ASC";}// SQL will look like this $sql = "SELECT * FROM table_name ORDER BY $filter $order";[/code] Quote Link to comment Share on other sites More sharing options...
Andrew R Posted August 18, 2006 Author Share Posted August 18, 2006 Thank you very much craygo. I have one more question. How would I add the sql query into an existing sql query (below). The reason I want to do this is because I have a pagination set-up so if I want the filter to work it needs to go through the pagination sql.[code]$query_users = "SELECT * FROM users ORDER by `id`LIMIT $start, $limit";$users = mysql_query($query_users, $conn_abrv) or die(mysql_error());$row_users = mysql_fetch_assoc($users);$totalRows_users = mysql_num_rows($users);[/code] Quote Link to comment Share on other sites More sharing options...
Woolf Posted August 19, 2006 Share Posted August 19, 2006 [quote author=Andrew R link=topic=104784.msg418299#msg418299 date=1155940251]Thank you very much craygo. I have one more question. How would I add the sql query into an existing sql query (below). The reason I want to do this is because I have a pagination set-up so if I want the filter to work it needs to go through the pagination sql.[code]$query_users = "SELECT * FROM users ORDER by `id`LIMIT $start, $limit";$users = mysql_query($query_users, $conn_abrv) or die(mysql_error());$row_users = mysql_fetch_assoc($users);$totalRows_users = mysql_num_rows($users);[/code][/quote]$query_users = "SELECT * FROM users ORDER BY $filter $order LIMIT $start, $limit"; Quote Link to comment Share on other sites More sharing options...
Andrew R Posted August 19, 2006 Author Share Posted August 19, 2006 Cheers 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.