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
https://forums.phpfreaks.com/topic/284219-php-if-statement-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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