Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need help with relevant searching. Percentage Searching perhaps?

    I need my code below to take the fields for checkboxes, radios, and combos, meaning select menus, and have them output relevant results. An example would if I wanted to find someone who has checkbox 1, 2, and 5 selected, it would show me users who first selected 1,2, and 5 first, and as I went down the results, it would show me, the users who selected 1, 2 and, so on. Basically the users who match my query 100% go topside, then 90% matching, then 80 percent matching, etc. Below is the code, perhaps it's a simple edit to this code below? I'm still new at PHP BTW.

    PHP Code:

    elseif ($profile_field['field_type'] == "checkbox")
                            {
                                
    $checkboxes = array();
                                if (isset(
    $_POST[$profile_field['field_label']])) {
                                    if ( 
    is_array($_POST[$profile_field['field_label']]) ) {
                                        
    $checkboxes = ( isset($_POST[$profile_field['field_label']]) ) ? $_POST[$profile_field['field_label']] : array();
                                    }
                                    else {
                                        
    $checkboxes = array($_POST[$profile_field['field_label']]);
                                    }
                                }
                                elseif (isset(
    $_GET[$profile_field['field_label']])) {
                                    if ( 
    is_array($_GET[$profile_field['field_label']]) ) {
                                        
    $checkboxes = ( isset($_GET[$profile_field['field_label']]) ) ? $_GET[$profile_field['field_label']] : array();
                                    }
                                    else {
                                        
    $checkboxes = array($_GET[$profile_field['field_label']]);
                                    }
                                }
                                foreach (
    $checkboxes as $item_id) {
                                    if ( 
    is_numeric($item_id) ) {
                                        
    $search_items[] = $item_id;
                                    }
                                }
                            }
                            elseif (
    $profile_field['field_type'] == "combo" || $profile_field['field_type'] == "radio")
                            {
                                
    $values = array();
                                if (isset(
    $_POST[$profile_field['field_label']])) {
                                    
    $values $_POST[$profile_field['field_label']];
                                }
                                elseif (isset(
    $_GET[$profile_field['field_label']])) {
                                    
    $values $_GET[$profile_field['field_label']];
                                }
                                if ( 
    is_array($values) && $values ) {
                                    
    $search_values = array();
                                    foreach ( 
    $values as $value ) {
                                        
    $search_values[] = $DB->add_slashes(trim($value));
                                    }
                                    if ( 
    $search_values ) {
                                        if ( 
    count($search_values) > ) {
                                            
    $search_fields[] = "d.data_".$field_label." IN (".implode(","$search_values).")";
                                        }
                                        else {
                                            
    $search_fields[] = "d.data_" $field_label "=" current($search_values);
                                        }
                                    }
                                }
                                elseif (
    $values) {
                                    
    $search_fields[] = "d.data_" $field_label "=" $DB->add_slashes(trim($values));
                                }
                            }
                            else
                            {
                                if (isset(
    $_POST[$profile_field['field_label']]) && trim($_POST[$profile_field['field_label']]))
                                    
    $search_fields[] = "d.data_" $field_label " LIKE '%" $DB->add_slashes(trim($_POST[$profile_field['field_label']])) . "%'";
                                elseif (isset(
    $_GET[$profile_field['field_label']]) && trim($_GET[$profile_field['field_label']]))
                                    
    $search_fields[] = "d.data_" $field_label " LIKE '%" $DB->add_slashes(trim($_GET[$profile_field['field_label']])) . "%'";
                            }
                        }

                        
    $j++;
                    }
                } 

  • #2
    New Coder
    Join Date
    Oct 2009
    Posts
    23
    Thanks
    1
    Thanked 0 Times in 0 Posts
    BUMP, is this too complicated for this community?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •