Jump to content

Recommended Posts

Hi

 

Think you want to AND rather than OR the different checks of fields.

 

However if doing that you need to only check against fields which do have a selected value.

 

<?php
$query = "SELECT DISTINCT a.id
FROM jos_users a
LEFT JOIN jos_community_users b ON a.id = b.userid
LEFT JOIN jos_community_fields_values c ON b.userid = c.user_id
";
$where = "";
$where .= (empty($gender))?"":sprintf(" (c.field_id=2 and c.`value`='%s') AND",mysql_real_escape_string($gender));
$where .= (empty($cities))?"":sprintf(" (c.field_id=10 and c.`value`='%s') AND",mysql_real_escape_string($cities));
$where .= (empty($height))?"":sprintf(" (c.field_id=18 and c.`value`='%s') AND",mysql_real_escape_string($height));
$where .= (empty($build))?"":sprintf(" (c.field_id=19 and c.`value`='%s') AND",mysql_real_escape_string($build));
$where .= (empty($sexuality))?"":sprintf(" (c.field_id=20 and c.`value`='%s') AND",mysql_real_escape_string($sexuality));
$where .= (empty($lookingfor))?"":sprintf(" (c.field_id=21 and c.`value`='%s') AND",mysql_real_escape_string($lookingfor));
$where .= (empty($membertype))?"":sprintf(" (c.field_id=22 and c.`value`='%s') AND",mysql_real_escape_string($membertype));
$where .= (empty($activities))?"":sprintf(" (c.`value`='%s') AND",mysql_real_escape_string($activities));
$query .= (!empty($where))?"WHERE ".substr($where,0,-3):"";
$result = mysql_query($query) or die($query.mysql_error());
?>

 

All the best

 

Keith

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.