Jump to content

Php If statement help


dsillaman

Recommended Posts

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;
Link to comment
Share on other sites

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.