dsillaman Posted November 24, 2013 Share Posted November 24, 2013 We need help. We currently have 2 search boxes on our search form. The first is a select box (not multiselect) and the 2nd is a city/state input box. When a search is being down based on an item selected from the select box and a particular city we are getting results back. However the results include all other members in our database that match the city, regardless of what is being selected. We know we are getting in the to select box because we can select a specific category and what is selected if it matches the city/state will be the first result. However we to refine the case selectbox query to only include resutls that specifically match what is selected from the select box. Here is our query code. We are thinking we need an IF statement but are not sure how to write it. Also the items in the select box are considered children. Can anybody on this forum help us. We are desperate. Thank you! function gmw_fl_query_fields($gmw) { global $bp, $wpdb; $total_fields = false; $total_fields = ( isset( $gmw['profile_fields'] ) ) ? $gmw['profile_fields'] : array(); if( isset( $gmw['profile_fields_date'] ) && !empty( $gmw['profile_fields_date'] ) ) array_unshift( $total_fields, $gmw['profile_fields_date'] ); if ( !isset($total_fields) || empty($total_fields) ) return; $empty_fields = array(); $userids = false; foreach ($total_fields as $field_id) { $field_data = new BP_XProfile_Field ($field_id); $fieldName = explode(' ', $field_data->name); $fieldName = preg_replace("/[^A-Za-z0-9]/","",$fieldName[0]); $children = $field_data->get_children (); $value = ( isset($_GET[$fieldName . '_'. $field_id]) ) ? $_GET[$fieldName . '_'. $field_id] : ''; $to = ( isset($_GET[$fieldName . '_' . $field_id. '_to']) ) ? $_GET[$fieldName . '_' . $field_id. '_to'] : ''; if ($value) array_push($empty_fields, $value); if( $value || $to || $children ) { switch ($field_data->type) { case 'selectbox': $sql = "SELECT user_id from {$bp->profile->table_name_data}"; $sql .= "WHERE field_id = $field_id"; $like = array(); foreach ($value as $curvalue) $like[] = "value = '$curvalue' OR value LIKE '%\"$curvalue\"%' "; $sql .= ' AND ('. implode (' OR ', $like). ')'; break; Quote Link to comment Share on other sites More sharing options...
Barand Posted November 24, 2013 Share Posted November 24, 2013 Sounds like you need to select those WHERE city = '$cityvalue' AND something = $dropdownvalue Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.