Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL Query instead of PHP If/Else

Posted on 2013-05-16
5
Medium Priority
?
419 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
The viewer will learn how to dynamically set the form action using jQuery.

719 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