|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
This is quite complicated. I do not know where to start because I havent reached the section on arrays in my book yet (its the nextchapter). MY boss wants this done asap though.
So I have two different tables (one name Countries and another Users). The users submit their preferences, one which includes what countries they have visited. That is fine and dandy. I have now created a search for the users so they can search the database for other users with different or similar countries visited. The problem is that in the users database the Country_Visited is stored as the country code, not the country itself, therefore if you search with a countries name it just won't work. (In the Countries table there are two columns, name and value. Name is the country code, value is the country name). How can I set it up so that when they search the table they can type in a country and it will search for that country in the table Users for which countries they have visited? |
|
#2
|
|||
|
|||
|
I think I have a solution.
What you should consider is creating a SELECT form object for the country search, and in it list all the countries, but use the country codes for the values Code:
<select name="country"> <option value="CODE">COUNTRY</option> ...repeat.... </select> Then, when you search with PHP, use this SQL PHP Code:
Hope this helps Note: Using your countries table, you can dynamically generate the SELECT object Last edited by beetle18 : July 11th, 2002 at 12:01 PM. |
|
#3
|
|||
|
|||
|
Wont work
I dont think that will work because it is in a separate table. In the users table it uses the country code. I need it to search for the country name, not the country code.
|
|
#4
|
|||
|
|||
|
Quote:
According to what you say above, the SQL and HTML/PHP I showed you should get your results. If the SELECT object is properly constructed (each CODE is matched up with the proper COUNTRY NAME) then searching the Users database with the value of the SELECT will get you the data you are after. I think what you are meaning to say is this "That you need is to search for the country code, but return the country name." I'm going to lay out some SQL here, and I will assume that your columns in the Countries table are 'Country_Name' and 'Country_Code' PHP Code:
Lemme know if this works! |
|
#5
|
|||
|
|||
|
Beetles Reply
Ok. This is what i need. I need the user to be able to type in the COUNTRY NAME and search for the COUNTRY NAME, notthe country code. IN the USERS table, the country code is stored, not the name
|
|
#6
|
|||
|
|||
|
I give up
I have tried my best to help you, but I don't think you have a sufficient understanding of the basics to tackle this problem. If you are still just understanding arrays, then some of the concepts here may be over your head.
The SQL statement I showed you is a simple table join. If you aren't familiar with JOINs in SQL, then read up on them. I recommended using the SELECT object for searching because that will prevent you from having to error-check that data (for example, if you just had an input field so people could type in the country, for USA you could get input like 'United States', 'USA', 'US', 'America', or who knows what else...maybe even input with spelling errors) I have tested the suggestion I gave you with two small sample tables I made. It does work. The ball is in your court, buddy. Best of luck. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Database Development > 2 different tables, same database..print prob |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|