I am having a form which contains some field(language,Datefrom,Dateto,Status).There is a submit button.I want to fetch the data based on the value filled on these field.My query to ignore the field which is not filled.How can i write the query.
Select * from tbldep where (language='$language') AND ( Date between '$Datefrom' AND '$Dateto')AND (status='$status')
My query to ignore the value which is not filled. Suppose user has not filled the value of date in DateFrom field in that case query should fetch the all record which are less than DateTo value.
2
Answers
IFNULL. If there is no date, replace the null with a default that will get the data you want.
You can use boolean logic – although that’s a bit lengthy to express:
Note that this uses bind parameters (with the
:
prefix) instead of string concatenation to build the query (which is unreliable and unsafe).