= '$afterdate'"; }
else { $sql = $sql." AND date >= NOW()"; }
if ($_POST[beforemonth] != 0 AND $_POST[beforeday] != 0) {
$beforedate = "$_POST[beforeyear]-$_POST[beforemonth]-$_POST[beforeday]";
$sql = $sql." AND date <= '$beforedate'";
}
} else {
$last_year = time() - 365*24*60*60;
$sql = $sql." AND date >= '".date('Y-m-d', $last_year)."'";
}
// regions are checkboxes that then check off all states within that region
// add states
if (isset($_POST[states])) {
$glue = "','";
$statelist = "('".implode($glue, $_POST[states])."')";
$sql = $sql." AND statetag IN $statelist";
}
// add distances
if (isset($_POST[points])) {
// convert the array to a SQL friendly format
$glue = ",";
$pointlist = "(".implode($glue, $_POST[points]).")";
$sql = $sql." AND pointclass IN $pointlist";
}
$sql = $sql." ORDER BY date ASC";
$results = mysql_query($sql);
$none = FALSE;
if (mysql_num_rows($results) == 0) {
$none = TRUE;
}
$race_count = mysql_num_rows($results);
// trim redundant keywords: triathlon, duathlon
$trim_words = array(" the ", " a ", " an ", "and ", " half ", "triathlon", "duathlon");
foreach ($trim_words AS $word) {
$_POST['keyword'] = str_ireplace($word, " ", $_POST['keyword']);
}
$bool_Keywords = false;
if (isset($_POST['keyword']) && $_POST['keyword'] != "") {
//keyword search
$bool_Keywords = true;
while($row_races = mysql_fetch_array($results)) {
// build an array that we can loop through.
$arr_Races[$i] = $row_races;
$i++;
}
$arr_Matches = array();
foreach ($arr_Races AS $race) {
if (stripos($race['name'], $_POST['keyword']) !== false) {
// push this onto the array of matches
$race['percent'] = 100;
array_push($arr_Matches, $race);
} else {
$name_nospace = str_replace(" ", "", $race['name']);
$keyword_nospace = str_replace(" ", "", $_POST['keyword']);
if (stripos($name_nospace, $keyword_nospace) !== false) {
// push this onto the array of matches
$race['percent'] = 90;
array_push($arr_Matches, $race);
} else {
// trim redundant keywords
$race_name = $race['name'];
foreach ($trim_words AS $word) {
$race_name = str_ireplace($word, " ", $race_name);
}
//$race_name = str_ireplace(" ", "", $race_name);
$race_name = strtolower($race_name);
$arr_race_name = explode(" ", $race_name);
$_POST['keyword'] = strtolower($_POST['keyword']);
$_POST['keyword'] = str_replace(" ", "", $_POST['keyword']);
foreach ($arr_race_name AS $test_word) {
similar_text($test_word, $_POST['keyword'], $percent);
if ($percent >= 65) {
// push this onto the array of matches
$race['percent'] = round($percent, 0);
//$race['trimmed'] = $race_name;
array_push($arr_Matches, $race);
break;
}
}
}
}
}
if (count($arr_Matches) == 0) {
$none = TRUE;
}
$race_count = count($arr_Matches);
//sort the array by keyword match success instead of by date
function cmp($a, $b)
{
if ($a['percent'] == $b['percent']) {
return 0;
}
return ($a['percent'] > $b['percent']) ? -1 : 1;
}
usort($arr_Matches, "cmp");
}
//end keyword search
// set the page title
$pagetitle = "Search Results";
// set meta tags
$meta_keywords = "triathlons in matching a user's search query.";
$meta_description = "A list of matching races.";
?>
include("include_common_head.php"); ?>
include($common_path . "/ads/ad_wallpaper.html"); ?>
include($common_path . "/templates/include_header.php"); ?>
include("include_breadcrumb.php"); ?>
include($common_path . "/templates/include_footer.php") ?>
include($common_path . "/templates/include_global_js.php") ?>