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:
  #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!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

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




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT