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! Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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; 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.