brendanm Posted July 23, 2007 Share Posted July 23, 2007 I'm brand new to PHP and have successfully created an SQL table, connected to it and then retrieved the data. Now I've got all my data back from the table using a select query, I want to be able to alter what is displayed. So, say I have a table with three fields: Name, Age and Nationality. When I query the table, I can retrieve all the data using SELECT * FROM tablename Now I want to filter those results to display only British people (from the nationality) field. I understand that I must use the WHERE function. No problem. I can query the table and retrieve just the British people. But how do I install a drop-down box on the page that allows me flick between various filter options. Is there an array or variable or something? I was wondering if there was a tutorial or some sample code which allowed a developer to filter in this way. Any advice for a noob greatly appreciated! Link to comment https://forums.phpfreaks.com/topic/61337-creating-a-drop-down-box-to-filter-query-results-in-a-table/ Share on other sites More sharing options...
DeadEvil Posted July 23, 2007 Share Posted July 23, 2007 Correct me if I'm wrong.. You want to put the result of the query inside the drop-down box? Link to comment https://forums.phpfreaks.com/topic/61337-creating-a-drop-down-box-to-filter-query-results-in-a-table/#findComment-305211 Share on other sites More sharing options...
brendanm Posted July 23, 2007 Author Share Posted July 23, 2007 No. As the query changes, the results in the table below change too. Link to comment https://forums.phpfreaks.com/topic/61337-creating-a-drop-down-box-to-filter-query-results-in-a-table/#findComment-305213 Share on other sites More sharing options...
DeadEvil Posted July 23, 2007 Share Posted July 23, 2007 I hope this is write... # create drop-down box <form action="action_page.php" method="post"> $query = mysql_query("select id, Nationality from tbl_name"); while($row = mysql_fetch_array($query)): $dropdown = "<select name=\"dp_name\"><option value=".$row['id'].">".$row['Nationality']."</option></select>"; endwhile; print $dropdown; # action page $query = mysql_query("select * from tbl_name WHERE Nationality = '{$_POST['dp_name']}'"); while($row = mysql_fetch_array($query)): # show record of selected query.... endwhile; Link to comment https://forums.phpfreaks.com/topic/61337-creating-a-drop-down-box-to-filter-query-results-in-a-table/#findComment-305216 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.