Solved

[MySQL+PHP] SELECT -> Ignore condition if zero rows?

Posted on 2011-03-04
3
717 Views
Last Modified: 2012-05-11
Hi,

I have this example mysql_query:

mysql_query("SELECT * FROM table WHERE id='$id' AND name NOT IN($names)");

Is there any option in mysql_query to get results even if this returns Zero rows, i.e. run query ignoring that second condition?

I know it's easy to use PHP if() but I'm just curious whether is possible to do it inside one mysql_query.

Thanks for ideas!
0
Comment
Question by:Aidam-Unlimited
[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
3 Comments
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 250 total points
ID: 35038083
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 35038438
you could do this:
mysql_query("SELECT * FROM table WHERE id='$id' AND ( name NOT IN($names) OR NOT EXISTS(  SELECT * FROM table WHERE id='$id' AND ( name NOT IN($names))  ))");

Open in new window

0
 

Author Closing Comment

by:Aidam-Unlimited
ID: 35069882
Thanks to both of you guys!
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

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.
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

733 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