Click here to Skip to main content
12,693,891 members (32,814 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: PHP MySQL
hi friends,

I want a query for search value taking multiple columns like any matrimonial site.

I'm using this query:
$query_for_result=mysql_query("select * from matri_user_info where (gender='$gender') and (age between $agemin and $agemax) and (height between $hmin and $hmax) and (religion='$religion') and (marital_status='$marital_status') and (city ='$city') and (state='$state') and (country='$country');");


But it show 0 result when some columns left blank because i take and and it will search by taking every variable value and if i take OR then it show any value even matched by any columns.

So i just want if user select even one the it show result according that if 2 then according that and so on.

If any of you have any idea then pls let me know.

thanks
Posted 6-Oct-12 2:29am
Updated 6-Oct-12 2:32am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Change your where condition:
where (gender='$gender') and (age between $agemin and $agemax)
becomes
where ($gender IS null OR gender='$gender') and ($agemin IS null OR $agemax IS null OR age between $agemin and $agemax)
And so on
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 6 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100