Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-05-2009, 10:09 AM   PM User | #1
crazyeights
New Coder

 
Join Date: Oct 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
crazyeights has a little shameless behaviour in the past
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++;
                }
            } 
crazyeights is offline   Reply With Quote
Old 11-05-2009, 11:44 PM   PM User | #2
crazyeights
New Coder

 
Join Date: Oct 2009
Posts: 23
Thanks: 1
Thanked 0 Times in 0 Posts
crazyeights has a little shameless behaviour in the past
BUMP, is this too complicated for this community?
crazyeights is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:49 PM.


Advertisement
Log in to turn off these ads.