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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.