Solved

MySQL Query instead of PHP If/Else

Posted on 2013-05-16
5
396 Views
Last Modified: 2013-05-16
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
Comment
Question by:mar2195
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:santoshmotwani
ID: 39173347
This will display records with US + NY

SELECT * FROM dealers WHERE Country = 'US' and City = 'NY'
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 39173512
SELECT * FROM dealers WHERE `Country`='US' and `State`='NY'
0
 

Author Closing Comment

by:mar2195
ID: 39173516
@santoshmotwani  ... thanks also.

FYI:  The BACKTICKS are not always necessary (at least in the testing that I completed).
0
 
LVL 16

Expert Comment

by:santoshmotwani
ID: 39173525
sorry i must be sleeping when i wrote above query  totally forgot NY is a state
0
 

Author Comment

by:mar2195
ID: 39173526
lol  ... it's a CITY also!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now