Database Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesDatabase Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old July 11th, 2002, 09:01 AM
hereford hereford is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 11 hereford User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to hereford
Question 2 different tables, same database..print prob

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?

Reply With Quote
  #2  
Old July 11th, 2002, 11:58 AM
beetle18 beetle18 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Victoria, TX
Posts: 29 beetle18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to beetle18 Send a message via AIM to beetle18
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:
 $sql "SELECT * FROM users WHERE Country_Visited=".$country;
$result mysql_query($sql); 

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.

Reply With Quote
  #3  
Old July 11th, 2002, 12:26 PM
hereford hereford is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 11 hereford User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to hereford
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.

Reply With Quote
  #4  
Old July 11th, 2002, 01:16 PM
beetle18 beetle18 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Victoria, TX
Posts: 29 beetle18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to beetle18 Send a message via AIM to beetle18
Question

Quote:
The problem is that in the users database the Country_Visited is stored as the country code, not the country itself

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:
 $sql="SELECT u.Name, c.Country_Name 
      FROM users u,countries c 
      WHERE c.Country_Code='"
.$country."' AND c.Country_Code = u.Country_Visited 
      GROUP BY u.Name"
;
$result mysql_query($sql); 

Lemme know if this works!

Reply With Quote
  #5  
Old July 11th, 2002, 02:10 PM
hereford hereford is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Posts: 11 hereford User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via AIM to hereford
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

Reply With Quote
  #6  
Old July 11th, 2002, 02:23 PM
beetle18 beetle18 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Victoria, TX
Posts: 29 beetle18 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to beetle18 Send a message via AIM to beetle18
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesDatabase Development > 2 different tables, same database..print prob


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five &quot;checkpoints&quot; for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway