Here's an abbreviated version of the code. The actual code is a lot longer. THANKS!
$query = "SELECT distinct a.username, a.sex, a.state, a.age, a.height, a.ethnicity, a.haircolor, a.last_login FROM profile as a, images as b WHERE";
$query .= " (a.sex in ('$sex'))";
if($state != All)
$query .= " AND (a.state in ('$state'))";
$query .= " AND (a.age between '$age1' and '$age2')";
$query .= " AND(a.height between '$height1' and '$height2')";
if(!empty($ethnicity1) or !empty($ethnicity2) or !empty($ethnicity3) or !empty($ethnicity4) or !empty($ethnicity5) or !empty($ethnicity6) or !empty($ethnicity7) or !empty($ethnicity8))
$query .= " AND (a.ethnicity in ('$ethnicity1 ','$ethnicity2 ','$ethnicity3 ','$ethnicity4 ','$ethnicity5 ','$ethnicity6 ','$ethnicity7 ','$ethnicity8','$ethnicity9'))";
if(!empty($haircolor1) or !empty($haircolor2) or !empty($haircolor3) or !empty($haircolor4) or !empty($haircolor5) or !empty($haircolor6) or !empty($haircolor7))
$query .= " AND (a.haircolor in ('$haircolor1 ','$haircolor2 ','$haircolor3 ','$haircolor4 ','$haircolor5 ','$haircolor6 ','$haircolor7 '))";
if(!empty($photo))
$query .=" AND a.username = b.username AND ( b.img_id != 0)";
$query .= " order by last_login desc";