Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 430
  • Last Modified:

MySQL Query instead of PHP If/Else

SITUATION:
After the user has selected the country "US" - they are then going to select a state (Example; NY) and SUBMIT - DB / PHP displays output.

I need either PHP or MySQL to parse out only the records that qualify: US + NY

Here is the Country query that I'm using:
SELECT * FROM dealers WHERE Country = 'US'

Open in new window

table: dealers
columns:
id
Dealer
Phone
City
State
Country

Obviously, I could use a php IF/ELSE to only display the selected State records.

Instead, I'm hoping there's a way to edit the query listed above to handle this.

Yes, I am a MySQL newbie.


Thanks.
0
mar2195
Asked:
mar2195
  • 2
  • 2
1 Solution
 
santoshmotwaniCommented:
This will display records with US + NY

SELECT * FROM dealers WHERE Country = 'US' and City = 'NY'
0
 
hieloCommented:
SELECT * FROM dealers WHERE `Country`='US' and `State`='NY'
0
 
mar2195Author Commented:
@santoshmotwani  ... thanks also.

FYI:  The BACKTICKS are not always necessary (at least in the testing that I completed).
0
 
santoshmotwaniCommented:
sorry i must be sleeping when i wrote above query  totally forgot NY is a state
0
 
mar2195Author Commented:
lol  ... it's a CITY also!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now