Jump to content

Help with sql query of a case select box


dsillaman

Recommended Posts

For some reason we can't seem to get our select box in our search from to query from the database and generate results. Here is the snipit of code. We have tested and tried to just duplicate the code for the case radio button because when we tried radio button instead of select box it worked perfectly . All of the data for both the selectbox and radio button are housed in the same database. Can anyone please help us.

 

Here is what we have that created the selectbox to begin with:

function gmw_fl_fields_dropdown($gmw, $id, $class) {

	$total_fields = ( isset($gmw['profile_fields']) ) ? $gmw['profile_fields'] : array();
	if( isset($gmw['profile_fields_date']) ) array_unshift($total_fields, $gmw['profile_fields_date']);

	echo '<div id="'.$id.'" class="'.$class.'">';

	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]);
		
		$get_field = (isset($_GET[$fieldName . '_' . $field_id])) ? $_GET[$fieldName . '_' . $field_id] : '';
		$get_field_to = (isset($_GET[$fieldName . '_' . $field_id. '_to'])) ? $_GET[$fieldName . '_' . $field_id. '_to'] : '';

		$children = $field_data->get_children ();

		switch ($field_data->type) {
			case 'datebox':
				echo '<div class="editfield field_'.$field_id.' datebox">';
				echo '<span class="label">Age Range (min - max)</span>';
				echo '<input size="3" type="text" name="'. $fieldName . '_' . $field_id.'" value="' . $get_field . '" placeholder="Min" style="width:10%" />';
				echo ' - ';
				echo '<input size="3" type="text" name="'. $fieldName . '_' . $field_id . '_to" value="' . $get_field_to . '" placeholder="Max" style="width:10%" />';
				echo '</div>';
				break;

			case 'multiselectbox':
			case 'selectbox':
				case 'selectbox':
				echo '<div class="field_'.$field_id.'selectbox">';
				echo '<span class="label">' . $field_data->name. '</span>';
				$tt = array();
				if($get_field) {
					$tt = $get_field;
					
				}
				echo '<select>';
				foreach ($children as $child) {
					$child->name = trim ($child->name);
					$selected =  (in_array ($child->name, $tt ) )? "selected='selected'": "";
					
					echo '<option ' .$selected . ' type="selectbox" name="'. $fieldName . '_' . $field_id. '[]" value="'.$child->name.'">'.$child->name.'</option>';
					
					//echo '<option value="'$selected . $child->name'"> . 'echo $child->name'</option>';
					//echo '<input ' .$selected . ' type="selectbox" name="'. $fieldName . '_' . $field_id. '[]" value="'.$child->name.'" />'.$child->name.'</select>';
				}
				echo '</select>';
				echo '</div>';
				break;

And here is the query code: Agan the radio button worked perfectly and we did try to duplicate that code for the select box and it didn't work. We are thinking that we are missing something related to an array or a $_GET action...

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 ) {
			
			switch ($field_data->type) {
					
				case 'selectbox':
					$category = $_GET ['$value'];
					$sql = "SELECT user_id from {$bp->profile->table_name_data}";
					$sql .= " WHERE field_id = $field_id ";
				        $sql .= ' AND ('. implode (' OR ', $category). ')';
				        
	 			break;
				
				case 'multiselectbox':
				case 'checkbox':
				case 'radio':
					
					$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

The "name" should be in the <select>... Not in the <option> tag.

 

Something like that:

echo '<select  name="fieldname">';

and

echo '<option ' .$selected . ' type="selectbox" value="'. $fieldName . '_' . $field_id. '">'.$child->name.'</option>';
Edited by BrodaNoel
Link to comment
Share on other sites

No,

I'm saying that <option> tag not have the "name" property... Is the <select> tag has that.

 

When you select a value in a <select> (combobox), you are "creating" a (only one) variable with the value that you are selected.

 

So, that is the problem for asnwer this:

"For some reason we can't seem to get our select box in our search from"

 

So, if you write the "name" property in the <option> tag, the variable not be going to be created.

 

Can you paste here the HTML generated (using the SELECT)? I need see what is "field name", "id_field" al more, for help me to help you.

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.