MySQL output corresponding rows - Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more
Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Webmaster Tech > Databases - MySQL, SQL, Oracle, Access and others

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 07-21-2011, 11:02 PM   #1 (permalink)
Junior Member
 
Join Date: Jul 2011
Posts: 1
Default MySQL output corresponding rows

HI friends..I have a tab delimited text file with country, city, Participants field.. Now, when I search for a particular entry for eg. Country England, then I want it to show all the cities associated with it Inot just one). My actual table looks like this--
Please check the Screenshot from my first attachment.
Now, If I select England from this MySQL table, then I want MySQL to display me all the corresponding cities for England.
Like this:
Please check the Screenshot from my second attachment.
Not this:
Please check the Screenshot from my third attachment.
One thing, all the rows with city names of the corresponding country is fixed to three.
I loaded the data using LOAD DATA LOCAL INFILE command to load them from my tab delimited text file.
Table created using VARCHAR with Default null..
Could you please tell me the appropriate command for this (like if there's any appropriate LIMIT command or something like that)
Thanks for your help..
Attached Images
File Type: jpg 2dceg4p.jpg (37.5 KB, 6 views)
File Type: jpg 1zbyoep.jpg (4.4 KB, 4 views)
File Type: jpg 2lvntsm.jpg (20.0 KB, 3 views)
ghosh24 is offline   Reply With Quote
Sponsored Links
Old 09-16-2011, 04:08 PM   #2 (permalink)
Junior Member
 
Join Date: Sep 2011
Location: Long Islanf, NY, USA
Posts: 33
Default Re: MySQL output corresponding rows

You have 2 cities, London and Taunton, with a country of England. You have 4 cities, Exeter, Leeds, Bristol and Plymouth (along with Melbourne, Kolkata and Mumbai) that have no countries. Your data is corrupt. Add the proper country to each row.

Then your select statement will be

"SELECT Cities FROM test2 WHERE Country = 'England';"

If you also want the country, make that

"SELECT Country, Cities FROM test2 WHERE Country = 'England';"

You can't select a blank country from a record that has a non-blank country, and you can't select based on a country if the record's Country field is blank.

If you want it displayed your way you'll have to write code (PHP if it's a website), to display the country name every third line. (You could also write some fairly complex SQL to do that.)
Rukbat is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 08:13 AM.


Powered by vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.2
Webmaster Forums
Web Hosting | Chicago Web Hosting | Web Hosting