quartney Posted December 1, 2006 Share Posted December 1, 2006 This is an easy php question but I'm having major difficulties figuring out the answer.I have a drop-down menu on the index page, where you can choose a country from a list. The results page should be names of people who live in that country.MySQL: My table "country" has two columns: countryName and countryID;My table "personal" has many columns, like name and address, as well as countryIDWhen a country name is chosen, I need to change that countryName into countryID. Then, I'll use the countryID to get the names of people who have that same countryID in the personal table.***My question is, where and when do I change the countryName into countryID?***I've got the index page sending a POST variable with the countryName, and the results page will list names of people who have the corresponding countryID, but I'm missing the crucial step of transforming the countryName into countryID.Many thanks for any help you can provide,Q. Quote Link to comment Share on other sites More sharing options...
craygo Posted December 1, 2006 Share Posted December 1, 2006 On your form page where they select the county make the value the countryID[code]<select name=countryid><option value=$countryID>$countryName</option>ect, ect,ect...</select>[/code]Then on the next page run your query[code]$sql = "SELECT * FROM personal JOIN country ON personal.countryID = country.countryID WHERE countryID = '".$_POST['countryid']."'";[/code]Ray Quote Link to comment Share on other sites More sharing options...
anner Posted December 1, 2006 Share Posted December 1, 2006 If the value being passed is the country ID, as in the code in the last post, you probably won't need a join, you'll probably just need your query to look like this:[code]$sql="Select * from personal where countryID = '".$_POST['countryid']."'";[/code] Quote Link to comment Share on other sites More sharing options...
quartney Posted December 1, 2006 Author Share Posted December 1, 2006 Craygo & Anner:thank you both so much! Your suggestions worked perfectly ;D 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.