dsillaman Posted November 21, 2013 Share Posted November 21, 2013 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; Quote Link to comment https://forums.phpfreaks.com/topic/284136-help-with-sql-query-of-a-case-select-box/ Share on other sites More sharing options...
BrodaNoel Posted November 21, 2013 Share Posted November 21, 2013 (edited) 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 November 21, 2013 by BrodaNoel Quote Link to comment https://forums.phpfreaks.com/topic/284136-help-with-sql-query-of-a-case-select-box/#findComment-1459363 Share on other sites More sharing options...
dsillaman Posted November 21, 2013 Author Share Posted November 21, 2013 BroadaNoel, So are you saying that should actually be in the area where we created the case selectbox? Not in the query area right? Quote Link to comment https://forums.phpfreaks.com/topic/284136-help-with-sql-query-of-a-case-select-box/#findComment-1459411 Share on other sites More sharing options...
BrodaNoel Posted November 26, 2013 Share Posted November 26, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/284136-help-with-sql-query-of-a-case-select-box/#findComment-1460202 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.