EHTISHAM Posted September 27, 2015 Share Posted September 27, 2015 How to use optional AND or skip AND condition in mySQL query when user enter submit null value for that condition.. SELECT * FROM tbluser WHERE gender='male' AND mother_tongue='Tamil' AND religion_id='3' AND caste_id='374' AND (age BETWEEN 50 AND 70); the database use doesn't have any null value.. So if user doesn't enter any value in any field then the query results null.... I am using this query for searching bride grooms in my matrimonial site(PHP).. If anyone know how to come out from this prob.. help me.. Thanks.. Link to comment Share on other sites More sharing options...
Dal1980 Posted September 27, 2015 Share Posted September 27, 2015 From what I've gathered you're saying that: SELECT * FROM tbluser WHERE gender='male' AND mother_tongue='Tamil' AND religion_id='3' AND caste_id='374' AND (age BETWEEN 50 AND 70); Could be: SELECT * FROM tbluser WHERE gender='' AND mother_tongue='' AND religion_id='' AND caste_id='374' AND (age BETWEEN 50 AND 70); Do I have that right? Link to comment Share on other sites More sharing options...
EHTISHAM Posted September 27, 2015 Author Share Posted September 27, 2015 From what I've gathered you're saying that: SELECT * FROM tbluser WHERE gender='male' AND mother_tongue='Tamil' AND religion_id='3' AND caste_id='374' AND (age BETWEEN 50 AND 70); Could be: SELECT * FROM tbluser WHERE gender='' AND mother_tongue='' AND religion_id='' AND caste_id='374' AND (age BETWEEN 50 AND 70); Do I have that right? as i mentioned earlier... the database use doesn't have any null value.. So if user doesn't enter any value in any field then the query results null.... so if gender is null the whole query results Null.. Link to comment Share on other sites More sharing options...
Barand Posted September 27, 2015 Share Posted September 27, 2015 Do not post multiple copies of the same question. Link to comment Share on other sites More sharing options...
Recommended Posts