简体   繁体   中英

Checking a values is null or not inside where condition MySQL

I have a advanced search form which passes many variables to another page next.php .

My question is I want to check the variable is null or not inside query .

Can i use like this or is there any function like this??

$price=$_GET['price'];
$query="SELECT * FROM products WHERE (if price!='' { $price; } )";

Simply i want is if $price is null , i do not want check in where condition because it affects results.

How to do this guys??

Give me a solution

Thankss

Just check BEFORE querying anything. Why would you waste time in generating query if you have nothing to generate with?

$price=$_GET['price'];
if($price !== NULL) {
   //do stuff
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM