Jump to content

How to use optional AND or skip AND condition in mySQL query when user enter submit null value for that condition..


EHTISHAM

Recommended Posts

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

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

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

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.