Jump to content

having a problem with retrieving results on php pages


quartney

Recommended Posts

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 countryID

When 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.
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
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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.