General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsDatabasesGeneral SQL 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 January 26th, 2011, 04:59 PM
mlmpros mlmpros is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Location: East Texas
Posts: 39 mlmpros User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 59 m 14 sec
Reputation Power: 13
Structure query to enable display of data from two tables

I'm compiling a database of spam IP addresses to enable me to beter analyze the data for general blocking and statistics by country. In the first table there are seven fields, one of which is a "country" field containing the two-letter country code. In the second table there are two fields: "code" containing the two-letter code and "name" containing the name of the country.

In the first table, the primary is "ip", while in the second table, the primary is "code".

The following works just fine on the query of the first table
Code:
$query = "SELECT * FROM badips WHERE ip LIKE '$search' OR code LIKE '$search' OR registry LIKE '$search' ORDER BY ip ASC";
$result=mysql_query($query)or die(mysql_error());


However, I'm stumped on how to structure the query so that I may display the country code and country name.

Reply With Quote
  #2  
Old March 12th, 2011, 01:18 PM
June7's Avatar
June7 June7 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Location: The Great Land
Posts: 256 June7 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 9 h 29 m 29 sec
Reputation Power: 8
Join the two tables:

SELECT badips.*, name FROM countries RIGHT JOIN badips ON countries.code = badips.country WHERE ... ;

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > Structure query to enable display of data from two tables


Developer Shed Advertisers and Affiliates


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

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


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.

© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap