...

View Full Version : Need help with relevant searching. Percentage Searching perhaps?



crazyeights
11-05-2009, 10:09 AM
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.




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) > 1 ) {
$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
11-05-2009, 11:44 PM
BUMP, is this too complicated for this community?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum