Solved

MySQL Query instead of PHP If/Else

Posted on 2013-05-16
5
398 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

911 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

23 Experts available now in Live!

Get 1:1 Help Now