HTML Form Creator—Search and Match: Search for Compatible Groups
This script is called match_.php
The HTML Form Creator—Search and Match: Search for Compatible Groups CMS script is one of a group of PHP scripts that handle both the administrative and end-user aspects of a general purpose HTML Form Creator that allows not just input boxes but multiple selection enabled select/option lists as well. In addition to the expectable editing scripts for both administrative and end-user functions, there's also a Search and Match script—the one on this page—so that users can use the scripts to find other users with various individual or group commonalities, including proximity searches, i.e., find all the users within various distances. There are even private messaging scripts in this Content Managemeny System (CMS). And the script on this page, match_.php, includes a word search as well as a proximity search based on zip codes and a criteria matching search.
The zipcode database that we used so we could have the data needed to create the proximity search script is free so they deserve this link. Thanks, guys. It contains latitudes and longitudes and zips (and other stuff) which is enough info to enable us to calculate distances between zipcodes as long as they are in the USA and not military. We stuck all 42000+ records into a MySQL database table that is nearly 3MB in size. Yes, there are better zipcode databases that are more up to date and have the military zipcodes as well, but they cost a bit and we didn't feel like paying. To get the records into the db, click here.
- HTML Form Creator
- Edit Options in HTML Form Creator Form
- Administrator Page for HTML Form Creator
End-User HTML Form Creator Scripts
- HTML Form Creator—Register with Captcha
- HTML Form Creator—View Profile
- HTML Form Creator—Edit Profile
- HTML Form Creator—Search and Match
- HTML Form Creator—Search and Match — Security
- HTML Form Creator—Search and Match — JavaScript
- HTML Form Creator—Search and Match — Form
- HTML Form Creator—Search and Match — PHP
- HTML Form Creator—Enter Record in Form
- HTML Form Creator—View Record in Form
- HTML Form Creator—Profile and Account Management
- HTML Form Creator—Login to Profile and Account Management
- HTML Form Creator—Logout of Profile and Account Management
- HTML Form Creator—Delete Group Account
- HTML Form Creator—Forgot User Name
- HTML Form Creator—Forgot Password
- HTML Form Creator—Form to Send Private Message
- HTML Form Creator—Send Private Message
- HTML Form Creator—Private Message Outbox
- HTML Form Creator—Private Message Inbox
- HTML Form Creator—Delete Private Message from Inbox
- HTML Form Creator—Delete Private Message from Outbox
- HTML Form Creator—Private Message Logout
- HTML Form Creator—Search and Match Session Monitoring
- HTML Form Creator—Configure File for Database Connection
- HTML Form Creator—Captcha Script for Registration and Login
Administrative HTML Form Creator Scripts
The purpose of this script is to provide a way in which the user can do searching and matching searches. There is a word/phrase search where any of the answer fields in the question and answer form can be searched. The administrator-designed form questions can be either the select/option list type or the text input type. One or both of these types may be found on any one form. In addition, the search/match app below contains input fields for Group Name (which can be merely an individual, of course, but we recommend that, in registering, you use a name like Sparkyboy rather than a real name—and don't have the group name be the same as the login username), City, State, and Zip Code. Users may input data in any or all of these for search/match purposes. Finally, there is the Proximity Search, where users may enter "Only find groups within 1000 miles of my group's zipcode" searches, and there are also several other distances to search by: 500, 200, 100, 50, 10, and 2 miles.
One may enter up to 10 search criteria—if you enter more, the 11th through whatever criteria will be discarded. When the application returns search results, it returns them in the order of relevance: the groups/individuals with the most criteria satisfied are displayed first. Any record that satisfies any criteria will be displayed—records need not satisfy all criteria.
Note that in both matching searches and word searches, you are allowed to search on the search results—this is called a subsearch. But in word searches, even though the first search is about finding a word or phrase anywhere in the records' answers in the database, all subsearches revert to matching searches with the 10 criteria and not word searches. We feel the app is most useful this way.
Even though Proximity Search, Group Name, City, State, and Zip Code plus several select/option list type option criteria may be entered, in matching searches none of the text input type input boxes are available for the search. Therefore, it behooves Administrators to create not only more questions using select lists and less using input boxes, but also select/option list questions that are specifically designed to elicit answers that will facilitate useful search/match action.
For example, there is an MC Search and Match script that has been specifically designed for MCs (Microcommunities), but it will work for any group matching purposes. That script and its form deal with groups matching criteria with other groups, including group configurations (characteristics of who is in it) and group preferences (smoking, drinking, pets, religion, religious openness, racial preferences, gay/straight, housing type sought, parenting preferences, employment, and willingness to relocate).
This script, Search and Match, has a script name of match_.php, and, except for the Proximity Search, Group Name, City, State, and Zip Code inputs, the rest of the form questions are variable and unpredictable. They depend on the Administrator's purpose when he or she created the form.
The Proximity Search, Group Name, City, State, and Zip Code inputs actually do NOT access the same MySQL table as the rest of the form questions. They access only the user data in the my_members table where user registration data is stored. The rest of the search and match script accesses the tables with text input and select/options questions and the table with users' answers.
Anyway, you can see that the MC matching and the script on this page have an essential difference. The MC search and match script is hard-wired, set in concrete. It has no Administrator-created form questions. All questions are pre-determined and set and unchangeable. Therefore the search/match scripts relating to these questions are easy to make so they fit the questions exactly. Example: "How many people in your group are males from 18 to 23 years old?" is a question users see when registering (there are dozens more). In the search and match form, which has been tested and works to help groups find compatible groups, the searchers will see a parallel search criterion matching that question: "Find groups with males from 18 to 23 years old in them." and there is a checkbox next to that criterion to allow you to choose to use that criterion.
Another example in the MC search and match script is an input of the select/options list type: "Personal Entertainment" is the subject. The options are "No preference", "Tolerant of neighbors' loud music or TV", "Not tolerant of neighbors' loud music or TV".
The MC search and match script forms are constructed so no answer = 0 in both the text input box questions and the select/options list questions. Users registering that do not answer the "How many people in your group are males from 18 to 23 years old?" question are selecting the default of 0, which is pre-selected and therefore visible. Likewise, "No preference" is the pre-selected option for all select/option list questons, and this has a 0 value as well. The MC search and match script's MySQL database table with user data in it therefore has no missing values, empty strings, or NULL values, but simply numbers from 0 to 99 for all the select/option list and text input questions, except for the Proximity Search, Group Name, City, State, and Zip Code inputs, which have strings.
On the other hand, our Search and Match script on this page has Administrator-created questions with option values that are the same options the user sees when filling out the form. If the user sees "What's your favorite color?" and gets "Red", Yellow", "Blue", "Green", "Black", and "Orange" to choose in a select list, a choice of "Blue" will stick the string "Blue" in the MySQL table.
With the above as a context, we will look at how to create questions that avoid the need for text input box use, since these cannot be used in search and match searches (although they WILL be searched in the Word Search area of this script).
Rather than a text input question of "Which political party do you favor?", make it a select/option list question and list the parties and throw in an "Other". Then use a text/input box to get their Other party by asking: "If Other, please enter its name."
Rather than a text input question of "How many people in your group are males from 18 to 23 years old?" (which only works good in a hard-wired, set-in-concrete form), make it a select/option list question and list the options that will gather this data the easiest: "None", "1", "2", "3", "4", and "More than 4".
Rather than a text input question of "Would you like to live forever?", make it a select/option list question and list the options that will gather this data the easiest: "No preference", "No", "Yes", "Maybe". Note that "No preference" is already the pre-selected default value for all administrator-created HTML form questions of the select/option list type, so that the db table has no missing values, empty strings, or NULL values, so you will not put this in as an option—it will be there automatically.
If you need the long list of religions for people to select from, use this list on our MC Search and Match page. The same goes for our State option list or whatever else you find convenient. If you want a lot of the group configuration questions as an administrator creating a form, there are dozens on that page—just remember to turn them from text input to select/option list questions, as already discussed. Ignore
the Proximity Search, Group Name, City, State, and Zip Code inputs in form creation, as this will be handled automatically in the search and match script on this page, and the relevant data will be accessed in the my_members table, not the user inputs table.
The script below is match_.php. It is copyrighted by MCS Investments, Inc., but you may use it to help groups find compatible groups, regardless of whether they are MC related. (You may not use it if the groups in question are in any way related to illegal activities, porn, hate groups, terrorism, etc.) We wish you luck in succeeding in finding compatible groups that can relate well together.
We are using the term "groups" a lot on this page. But you may substitute the word "people" or "individuals. You may wish to use the HTML Form Creator CMS system for the purposes of people finding other people and then after searching and matching use the Private Messaging scripts to contact the people found in the search results. This may be for romantic, friendship, roommate finding purposes or whatever. If it's for sex-related purposes (legal, consentual, 18+, nonexploitative, no-money-involved), that's fine, but don't tell us about it—we blush easily!
Obviously, you may use the HTML Form Creator CMS system for other uses where the Search and Match aspects are not needed. You can put together survey forms (but you are better off with our PHP Poll and Script to Add Poll Vote to Database). For more on HTML forms, see http://www.w3.org/TR/html4/interact/forms.html and http://en.wikipedia.org/wiki/Form_(web). Forms are mostly used as part of the following processes: registration, login, purchasing products, guestbooks, Forum CMS,
Blog CMS, Address Book CMS,
Private Messaging CMS,
Chat Room CMS.
Other sites may have form creators, but we are the first we know of that has it integrated into a CMS system with login, registration, private messaging, and search and match scripts. Enjoy!
Use the following links to get to tutorials on the various coding aspects of the script below:
- HTML Form Creator—Search and Match — Security
- HTML Form Creator—Search and Match — JavaScript
- HTML Form Creator—Search and Match — Form
- HTML Form Creator—Search and Match — PHP
The script below is called match_.php
<?php
//copyright (c) 2011 by MCS Investments, Inc. all rights reserved
include_once"checkid_.php";
$U=$_SESSION['username'];
define('_NODIRECTACCESS', TRUE);
include_once"includes/config.php";
if (!isset($_SESSION['groupname']) || !isset($_SESSION['userid']) || !isset($_SESSION['username']) || $_SESSION
['username']<>$U || !isset($U) || $U=="" || strlen($U)<6 || !isset($_SESSION['sessionid'])){echo '<script language="javascript">alert("Please login."); window.location = "login_.php";</script>';}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Search and Match</TITLE>
<meta name="description" content="Search and Match">
<meta name="keywords" content="Search and Match,Search and Matching,info,match">
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left}
p, li, input {font:13px Verdana; color:black;text-align:left}
#j td {font:normal 13px Verdana;color:black;text-align:left;padding:0 6px 0 6px}
.l {text-align:left;margin-left:200px}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
h3 {font:bold 20px Verdana;}
b {text-align:center;}
.c {background-color:#ccc}
.k {text-align:right}
.i {text-align:right;width:100px}
.j {position:absolute;top:0px;left:150px;width:700px}
.m {margin-left:130px}
#y {margin-top:0px;width:600px}
#t {margin:50px 0 0 0;border:2px solid blue;background-color:#ddd;width:900px}
#j {margin:0px 0 0 0;table-layout:fixed}
#myform {position:absolute;top:120px;left:50px;width:900px;border:2px solid black;background-color:#8aa;}
.submit {font:bold 13px Verdana;color:blue;max-width:120px;width:120px;text-align:center;padding:0;}
.submit2 {font:bold 13px Verdana;color:blue;max-width:240px;width:240px;text-align:center;padding:0;}
#getdbname {position:absolute;top:104px;left:353px;}
.title {position:absolute;top:10px;left:130px;width:842px;text-align:center;}
.info {position:absolute;top:238px;left:2px;width:160px;background-color:#bbb;border:1px solid blue;padding:5px;text-align:left;}
</style>
<script language="javascript">
function c(){
var g=document.formpw.Willing_to_relocate;
for (var z=0; z<g.length; z++){
g[z].onclick=function(){var num=0;
for(var q=0;q<g.length;q++){num+=(g[q].checked);}
if (num>1){alert("Select one checkbox only, please, in \"Willing to relocate\"")
this.checked=false;}}}}
function again(){window.location="match_.php?searchtype=word";}
function validatepassword(){
var x=0;var a=new Array();var b=new Array();
var e=document.getElementsByTagName("input");
for(var i=0;i<e.length;i++){
if(e[i].checked==true && e[i].type=="checkbox"){a[x]=e[i].name;b[x]=e[i].value;x++;
if(x>10){a=a.slice(0,10);b=b.slice(0,10);}}}
if(x>10){alert("Only 10 criteria, please. Your 11th through "+x+"th criteria were discarded.");}
if(x>0){document.formpw.fieldname.value = a.toString();
document.formpw.fieldvalue.value = b.toString();}
if(document.formpw.city.value.length>0){
var ck_city = /^[A-Za-z\s\-]{2,33}$/;
if (document.formpw.city.value.search(ck_city)==-1)
{alert("Please only enter 2 to 33 letters, space, or hyphen for city name.");document.formpw.city.focus();return false}}
if(document.formpw.state.value.length>0){
var ck_state = /^[A-Za-z]{2,2}$/;
if (document.formpw.state.value.search(ck_state)==-1)
{alert("Please select a State.");document.formpw.state.focus();return false}}
if(document.formpw.zip.value.length>0){
var ck_zip = /^[0-9]{5,5}$/;
if (document.formpw.zip.value.search(ck_zip)==-1)
{alert("Please only enter 5 number zip code.");document.formpw.zip.focus();return false}}
if(document.formpw.groupname.value.length>0){
var ck_groupname = /^[A-Za-z0-9_]{6,20}$/;
if (document.formpw.groupname.value.search(ck_groupname)==-1)
{alert("Please only enter 6 to 20 letters, numbers and underline for group name.");document.formpw.groupname.focus();return false}}
return true;}
function saveresults(){alert("To save a record of your search results, go to your browser's File menu and select Save As, then choose Webpage, HTML only, except in Chrome, where you need to choose Webpage, Complete. On Mac Safari, save as Web Archive.");}
function checkdb(){
var ck_item3 = /^[A-Za-z0-9_]{3,20}$/;
if (document.nameform.db.value.search(ck_item3)==-1)
{alert("Please enter 3 to 20 letters, numbers, or underscore."); document.nameform.db.focus();return false;}}
mactest=(navigator.userAgent.indexOf("Mac")!=-1)
Netscape=(navigator.appName.indexOf("Netscape") != -1)
msafari=(navigator.userAgent.indexOf("Safari")!= -1)
wsafari=0; if(!mactest&&msafari){wsafari=1;msafari=0}
is_opera = 0; if(window.opera){is_opera=1}
is_ie_mac = 0; is_ie=0;if(document.all){is_ie=1}
if(is_ie&&mactest){is_ie_mac=1}
function fixwidth(){if(!mactest&&Netscape){
var e=document.getElementsById('myform');e.style.top='-80px';}
if(!mactest&&Netscape){
var e=document.getElementsByTagName("table");
for(var i=0;i<e.length;i++){e[i].style.marginTop='-440px';}}
if(mactest&&msafari&&!is_ie_mac){
var e=document.getElementsByTagName("table");
for(var i=0;i<e.length;i++){e[i].style.marginTop='-330px';}}
if(mactest&&!msafari&&is_ie_mac){alert("This browser is dead. Please use Firefox or Safari.");}
}
</script>
</head>
<body onload="fixwidth()">
<?php
function get_record_wordsearch($id,$score2){
global $i1,$aa,$a,$i2,$r,$h,$score2;
$result = mysql_query("SELECT * FROM my_members WHERE id = '$id'") or die(mysql_error());
$num=mysql_num_rows($result);
if($num>0){
$row = mysql_fetch_array($result);
echo "<center><div id='t'><table border='2' id='j'><col width='470'><col width='330'>";
echo "<tr><td colspan='2' style='text-align:center;color:red'>(click link to send message) <b><span style='color:black'>Group Name:</span> <a HREF='send-message-form_.php?gr=".htmlentities(stripslashes($row['groupname']), ENT_QUOTES)."'>".htmlentities(stripslashes($row['groupname']), ENT_QUOTES)."</a></b> (word search results)</td></tr><br>";
echo "<tr><td colspan='2' style='text-align:center'><b>Location: ".htmlentities(stripslashes($row['city']), ENT_QUOTES).", ";
echo htmlentities(stripslashes($row['state']), ENT_QUOTES)." ";
echo htmlentities(stripslashes($row['zip']), ENT_QUOTES)."</b></td></tr><br>";
$score2=0;echo "<tr><th width='470' align='center'>Questions</th><th width='330' align='center'>Answers</th></tr>";
$sql=mysql_query("SELECT * FROM $aa WHERE member_id='$id'");
while($row = mysql_fetch_array($sql)){
for ($h = 0; $h < count($i2); $h++) {$r=$row[$i2[$h]];theoptions_wordsearch();}}
echo "<tr><td colspan='2'><center>(this group has ".$score2." of that search word)</center></td></tr></table><center><BR></center></div>";
}}
function highlight() {
global $x, $S, $cm;
if (strlen($x) < 1 || strlen($S) < 1) {return;}
preg_match_all("/$S+/i", $x, $matches);
if (is_array($matches[0])){$cm=count($matches[0]);}
if (is_array($matches[0]) && $cm >= 1) {
foreach ($matches[0] as $match) {
$x = str_replace($match, '<span style="background-color:lightblue;">'.$match.'</span>', $x);
}}}
function theoptions_wordsearch(){
global $i1,$i2,$h,$aaa,$a,$r,$S,$x,$cm,$score2;
$sql = mysql_query("SELECT options FROM $aaa WHERE field_name='$i2[$h]'") or die(mysql_error());
$number_rows = mysql_num_rows($sql);
if($number_rows==0){
echo "<tr><td width='470' align='left'><span style='color:red'>*</span>".$i1[$h];
echo "</td><td width='330' align='left'>";
$x=$r;highlight();$score2=$score2+$cm;echo $x."</td></tr>";
}else{
echo "<tr><td width='470' align='left'><span style='color:red'>*</span>".$i1[$h];
echo "</td><td width='330' align='left'>";
$j=explode(",",htmlentities(stripslashes($r), ENT_QUOTES));
for ($d=0;$d<count($j);$d++){
$x=$j[$d];highlight();$score2=$score2+$cm;echo $x."<BR>";}
echo "</td></tr>";}}
function theoptions(){
global $i1,$i2,$h,$aaa,$a,$r;
$sql = mysql_query("SELECT options FROM $aaa WHERE field_name='$i2[$h]'") or die(mysql_error());
$number_rows = mysql_num_rows($sql);
if($number_rows==0){
echo "<tr><td width='470' align='left'><span style='color:red'>*</span>".$i1[$h];
echo "</td><td width='330' align='left'>";
echo $r."</td></tr>";
}else{
echo "<tr><td width='470' align='left'><span style='color:red'>*</span>".$i1[$h];
echo "</td><td width='330' align='left'>";
$j=explode(",",htmlentities(stripslashes($r), ENT_QUOTES));
for ($d=0;$d<count($j);$d++){
echo $j[$d]."<BR>";}
echo "</td></tr>";}}
function thecheckboxes(){
global $i1,$i2,$aaa;
for ($h=0;$h<count($i1);$h++){
$sql = mysql_query("SELECT options FROM $aaa WHERE field_name='$i2[$h]'") or die(mysql_error());
$number_rows = mysql_num_rows($sql);
if($number_rows>0){
$row=mysql_fetch_row($sql);
$r=$row[0];
echo "<tr><td colspan='2'><hr></td></tr><tr><td class='k'> </td><td align='left'><b style='color:blue'>".$i1[$h]."</b></td></tr>";
$j=explode(",",htmlentities(stripslashes($r), ENT_QUOTES));
for ($d=0;$d<count($j);$d++){
echo "<tr><td class='k'><input type='checkbox' name='".$i2[$h]."' value='".$j[$d]."'></td><td>".$j[$d]."</td></tr>";}
echo "<tr><td colspan='2'><br></td></tr>";
}}}
function underscore(){
global $i1,$i2;
$replacement="_";
$pattern9 = '/[^A-Za-z0-9_]/i';
for ($h = 0; $h < count($i1); $h++) {
$i2[$h]=preg_replace($pattern9, $replacement, $i1[$h]);$i2[$h]=str_replace("_middot_","_",$i2[$h]);}}
function milesapart($lat1,$long1,$lat2,$long2){
$miles = sin(deg2rad($lat1))
* sin(deg2rad($lat2))
+ cos(deg2rad($lat1))
* cos(deg2rad($lat2))
* cos(deg2rad($long1-$long2));
$miles = (rad2deg(acos($miles))) * 69.09;
return $miles;}
function coords($z1,$z2){
$res=mysql_query("SELECT latitude,longitude,class FROM zipcodes WHERE zipcode = '$z1'") or die(mysql_error());
$row = mysql_fetch_array($res);$lat1=$row['latitude'];$long1=$row['longitude'];$c1=$row['class'];
$res=mysql_query("SELECT latitude,longitude,class FROM zipcodes WHERE zipcode = '$z2'") or die(mysql_error());
$row = mysql_fetch_array($res);$lat2=$row['latitude'];$long2=$row['longitude'];$c2=$row['class'];
if($c1<>"MILITARY" && $c2<>"MILITARY" && $lat1<>0 && $long1<>0 && $lat2<>0 && $long2<>0){
$zz=milesapart($lat1,$long1,$lat2,$long2);
}else{$zz=9999;}
return $zz;}
function restorem(){
global $first;
for ($i=0;$i<count($first);$i++) {
$sql="UPDATE my_members SET score=1 WHERE id='$first[$i]'";
$result=mysql_query($sql);}}
function get_record($id,$score){
global $i1,$aa,$a,$i2,$r,$h;
$result = mysql_query("SELECT * FROM my_members WHERE id = '$id'") or die(mysql_error());
$num=mysql_num_rows($result);
if($num>0){
$row = mysql_fetch_array($result);
echo "<center><div id='t'><table border='2' id='j'><col width='470'><col width='330'>";
echo "<tr><td colspan='2' style='text-align:center;color:red'>(click link to send message) <b><span style='color:black'>Group Name:</span> <a HREF='send-message-form_.php?gr=".htmlentities(stripslashes($row['groupname']), ENT_QUOTES)."'>".htmlentities(stripslashes($row['groupname']), ENT_QUOTES)."</a></b> (fills ".$score." of your criteria)</td></tr><br>";
echo "<tr><td colspan='2' style='text-align:center'><b>Location: ".htmlentities(stripslashes($row['city']), ENT_QUOTES).", ";
echo htmlentities(stripslashes($row['state']), ENT_QUOTES)." ";
echo htmlentities(stripslashes($row['zip']), ENT_QUOTES)."</b></td></tr><br>";
echo "<tr><th width='470' align='center'>Questions</th><th width='330' align='center'>Answers</th></tr>";
$sql=mysql_query("SELECT * FROM $aa WHERE member_id='$id'");
while($row = mysql_fetch_array($sql)){
for ($h = 0; $h < count($i2); $h++) {$r=$row[$i2[$h]];theoptions();}}
echo "</table><center><BR></center></div>";
}}
$d=mysql_real_escape_string($_POST['db']);if(strlen($d)>2){
$db=$d;$aa=$db."_database";$exists = mysql_query("SHOW TABLES LIKE '$aa'") or die(mysql_error());
$_SESSION['db']=$db;$num_rows = mysql_num_rows($exists);
if($num_rows==0){unset($_SESSION['db']);unset($db);unset($d);mysql_close();
echo '<script language="javascript">alert("Table does not exist. Try again");</script>';}}
if(!isset($_SESSION['db'])){
echo "<div id='getdbname'><form name='nameform' id='nameform' method='post' action='match_.php' onsubmit='return checkdb()'>db name <input type='text' id='db' name='db' maxlength='20' size='20'><input type='submit' value='submit'></form></div>";}
if(isset($_SESSION['db'])){$db=$_SESSION['db'];
$dist=array(0,0,1000,500,200,100,50,10,2,0);
$id=$_SESSION['userid'];
$i1=array();$i2=array();$j=array();
$a=$db."_inputs";$aa=$db."_database";$aaa=$db."_options";
$sql=mysql_query("SELECT item FROM $a ORDER BY N");
$num_rows = mysql_num_rows($sql);
while($row = mysql_fetch_array($sql)){
array_push ($i1, htmlentities(stripslashes($row['item']), ENT_QUOTES));}
underscore();
$R=$_GET['searchtype'];
if($R<>"all" && $R<>"first" && $R<>"word"){$R="all";}
$S=$_POST['search'];
if($R=="word" && isset($S)){
if (strlen($S)<3) {echo '<script language="javascript">alert("Enter longer search terms.");window.location="match_.php?searchtype=word";</script>';unset($S);
}else{
$S=strip_tags($S);
$pattern2 = '/[^a-zA-Z0-9\\s\\.\\,\\!\\?]/i';
$replacement = '';
$S=preg_replace($pattern2, $replacement, $S);
$S=mysql_real_escape_string($S);
$gotwordmatch=0;
$sql="UPDATE my_members SET score=0";
$result=mysql_query($sql);
for ($h = 0; $h < count($i1); $h++) {$z=0;
$r=mysql_query("SELECT member_id,$i2[$h] FROM $aa WHERE $i2[$h] LIKE '%$S%'") or die('Error ,search failed');
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotwordmatch=1;
while($row = mysql_fetch_array($r)){
$word=$row[$i2[$h]];
$z=substr_count($word,$S);
$ID=$row['member_id'];
$sql="UPDATE my_members SET score=score+$z WHERE id='$ID'";$result=mysql_query($sql);}}}
if ($gotwordmatch==0){echo '<script language="javascript">alert("The search was unsuccessful.");</script><center><a HREF="match_.php?searchtype=word">Search Again for a Word</a> <a HREF="match_.php?searchtype=all">Search All</a></center>';unset($S);
}else{
echo "<BR><BR><BR><BR>";
$rr=mysql_query("SELECT id,score FROM my_members WHERE score>0 ORDER BY score DESC LIMIT 30");
while($row = mysql_fetch_array($rr)){
$id=$row['id'];
$score=$row['score'];
get_record_wordsearch($id,$score);}
echo '<span style="background-color:red"><b>You got '.mysql_num_rows($rr).' results.</b></span> <a HREF="match_.php?searchtype=word">Search Again</a> <a HREF="match_.php?searchtype=all">Search All</a>';unset($S);
}}
}else
if($R=="word" && !isset($S)){
echo '<div class="title">
<h1>Search Groups for Word/Phrase</h1>
<form method="post" action="match_.php?searchtype=word">
<table width="700" border="0" cellpadding="2" cellspacing="2" align="center">
<tr>
<td width="130">Search for:</td>
<td width="570"><input name="search" type="text" size="100"></td>
</tr>
<tr>
<td></td><td><input name="retrieve" type="submit" class="submit2" value="Search for word or exact phrase">
</td>
</tr>
</table>
</form>
</div>
<div id="info" class="info">No hyphens (-) or underscores (_) or Enter/Return allowed in search terms. Use letters, numbers, spaces and these: <B> , . ? ! </b> in searches. Relevancy will determine the order of groups returned as search results—whatever group has the most word matches will be displayed first as it is the most relevant to your search.<br></div>';
}
$Entry=$_POST['entry'];
if($Entry==1){
$replacement = '';
$fieldname = $_POST['fieldname'];
$fieldvalue = $_POST['fieldvalue'];
$relocate=0;$nolocate=0;$gotmatchrelocate=0;$gotmatch=0;
if(strlen($fieldvalue)<>0){
$pattern7= '/[^a-zA-Z0-9\\_\\,]/i';
$pattern8='/[^A-Za-z0-9\\!\\?\\$\\%\\(\\)\\_\\s\\.\\-\\·\\,]/i';
$fieldname=strip_tags($fieldname);
$fieldname=preg_replace($pattern7, $replacement, $fieldname);
$fieldvalue=strip_tags($fieldvalue);
$fieldvalue=preg_replace($pattern8, $replacement, $fieldvalue);
$fieldnames = explode(',',$fieldname);
$fieldvalues = explode(',',$fieldvalue);
for($i=0;$i<count($fieldvalues);$i++){
if($fieldnames[$i]=="Willing_to_relocate"){$ii=$i;$relocate=$dist[$fieldvalues[$i]];
}}
if($relocate>0 && count($fieldvalues)==1){unset($fieldvalue);unset($fieldname);}
if($relocate>0){unset($fieldvalues[$ii]);unset($fieldnames[$ii]);$fieldvalues=array_values($fieldvalues);$fieldnames=array_values($fieldnames);}}
$r=mysql_query("SELECT zip FROM my_members WHERE username='$U'");
$row = mysql_fetch_array($r);
$z1=$row['zip'];
if($R=="first"){
$first=array();
$r=mysql_query("SELECT id FROM my_members WHERE score>0 ORDER BY score DESC LIMIT 30");
while($row = mysql_fetch_array($r)){
array_push ($first, $row[0]);}}
$G=$_POST['groupname'];
$C=$_POST['city'];
$S=$_POST['state'];
$Z=$_POST['zip'];
$G=substr($G,0,20);
$C=substr($C,0,33);
$S=substr($S,0,2);
$Z=substr($Z,0,5);
$pattern1 = '/[^a-zA-Z\\-\\s]/i';
$pattern3 = '/[^a-zA-Z0-9\\_]/i';
$pattern5 = '/[^0-9]/';
$pattern6 = '/[^A-Z]/';
$G=strip_tags($G);
$C=strip_tags($C);
$S=strip_tags($S);
$Z=strip_tags($Z);
$C=preg_replace($pattern1, $replacement, $C);
$Z=preg_replace($pattern5, $replacement, $Z);
$G=preg_replace($pattern3, $replacement, $G);
$S=preg_replace($pattern6, $replacement, $S);
if (strlen($G)<6&&strlen($G)>0) {restorem();echo '<script language="javascript">alert("Please enter 6 to 20 characters for group name."); window.location = "match_.php?searchtype='.$R.'"; </script>';
}else{
if (strlen($C)<2&&strlen($C)>0) {restorem();echo '<script language="javascript">alert("Please enter 2 to 33 characters for city."); window.location = "match_.php?searchtype='.$R.'"; </script>';
}else{
if ((strlen($S)<2 || strlen($S)>2)&&strlen($S)>0) {restorem();echo '<script language="javascript">alert("Please use dropdown list for state."); window.location = "match_.php?searchtype='.$R.'"; </script>';
}else{
if (strlen($Z)<5&&strlen($Z)>0) {restorem();echo '<script language="javascript">alert("Please enter 5 digits for zip code."); window.location = "match_.php?searchtype='.$R.'"; </script>';
}else{
//SEARCH HERE
$gotmatch=0;
$sql="UPDATE my_members SET score=0";
$result=mysql_query($sql);
if($R=="all"){$gotmatch=-1;
if(strlen($G)>0){
$r=mysql_query("SELECT id FROM my_members WHERE groupname='$G'");
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;
while($row = mysql_fetch_array($r)){
$ID=$row['id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";$result=mysql_query($sql);}}}
if(strlen($C)>0){
$r=mysql_query("SELECT id FROM my_members WHERE city='$C'");
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;
while($row = mysql_fetch_array($r)){
$ID=$row['id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";$result=mysql_query($sql);}}}
if(strlen($S)>0){
$r=mysql_query("SELECT id FROM my_members WHERE state='$S'");
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;
while($row = mysql_fetch_array($r)){
$ID=$row['id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";$result=mysql_query($sql);}}}
if(strlen($Z)>0){
$r=mysql_query("SELECT id FROM my_members WHERE zip='$Z'");
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;
while($row = mysql_fetch_array($r)){
$ID=$row['id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";$result=mysql_query($sql);}}}
if(strlen($fieldvalue)<>0){$gotmatch=-1;
for($i=0;$i<count($fieldvalues);$i++){
if($fieldvalues[$i]<>"-1"){
$v=$fieldvalues[$i];
$r=mysql_query("SELECT member_id FROM $aa WHERE $fieldnames[$i] LIKE '%$v%'");}
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;}
while($row = mysql_fetch_array($r)){
$ID=$row['member_id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";
$result=mysql_query($sql);}}}
}else{$gotmatch=-1; //the else is if $R=="first" -- so below is if it's "first"
for($i=0;$i<count($first);$i++){
$sql="UPDATE my_members SET score=1 WHERE id='$first[$i]'";
$result=mysql_query($sql);}
if(strlen($G)>0){
$r=mysql_query("SELECT id FROM my_members WHERE groupname='$G' AND score>0");
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;
while($row = mysql_fetch_array($r)){
$ID=$row['id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";$result=mysql_query($sql);}}}
if(strlen($C)>0){
$r=mysql_query("SELECT id FROM my_members WHERE city='$C' AND score>0");
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;
while($row = mysql_fetch_array($r)){
$ID=$row['id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";$result=mysql_query($sql);}}}
if(strlen($S)>0){
$r=mysql_query("SELECT id FROM my_members WHERE state='$S' AND score>0");
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;
while($row = mysql_fetch_array($r)){
$ID=$row['id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";$result=mysql_query($sql);}}}
if(strlen($Z)>0){
$r=mysql_query("SELECT id FROM my_members WHERE zip='$Z' AND score>0");
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;
while($row = mysql_fetch_array($r)){
$ID=$row['id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID'";$result=mysql_query($sql);}}}
if(strlen($fieldvalue)<>0){$gotmatch=-1;
for($i=0;$i<count($fieldvalues);$i++){
if($fieldvalues[$i]<>"-1"){
$v=$fieldvalues[$i];
$l=$aa.".member_id";
$q=$aa.".".$fieldnames[$i];
$r=mysql_query("SELECT member_id FROM $aa LEFT JOIN my_members ON my_members.id = $l WHERE my_members.score>0 AND $q LIKE '%$v%'") or die(mysql_error());}
$num_rows = mysql_num_rows($r);
if($num_rows>0){$gotmatch=1;}
while($row = mysql_fetch_array($r)){
$ID=$row['member_id'];$sql="UPDATE my_members SET score=score+1 WHERE id='$ID' AND score>0";$result=mysql_query($sql);}}}
if($gotmatch==1){$sql="UPDATE my_members SET score=score-1 WHERE score>0";$result=mysql_query($sql);}
}//the end of the else that is if $R=="first" (the stuff below is for either "first" or "all")
if ($gotmatch<1 && $relocate==0){restorem();echo '<script language="javascript">var answer = confirm ("No results were found. If you want to Search Your Results, click OK. If you want to Search All, click Cancel.");if (answer){window.location = "match_.php?searchtype='.$R.'";}else{window.location = "match_.php";} </script>';
}else{
if($gotmatch==1 && $relocate==0){$nolocate=1;}
$gotmatchrelocate=0;
if($gotmatch==1 && $relocate>0){
$nolocate==0;$w=-1;if($R=="first"){$w=0;};
$r=mysql_query("SELECT id,zip FROM my_members WHERE score>'$w'");
while($row = mysql_fetch_array($r)){
$id=$row['id'];$z2=$row['zip'];$zz=coords($z1,$z2);
if($relocate>=$zz){$sql="UPDATE my_members SET score=score+1 WHERE id='$id' AND score>'$w'";$result=mysql_query($sql);$gotmatchrelocate=mysql_affected_rows();
}else{
$sql="UPDATE my_members SET score=0 WHERE id='$id'";$result=mysql_query($sql);
}}
if($w==0){$sql="UPDATE my_members SET score=score-1 WHERE score>0";$result=mysql_query($sql);}}
if($gotmatch<1 && $relocate>0){
$nolocate==0;$w=-1;if($R=="first"){$w=0;};
$r=mysql_query("SELECT id,zip FROM my_members WHERE score>'$w'");
while($row = mysql_fetch_array($r)){
$id=$row['id'];$z2=$row['zip'];$zz=coords($z1,$z2);
if($relocate>=$zz){$sql="UPDATE my_members SET score=score+1 WHERE id='$id' AND score>'$w'";$result=mysql_query($sql);$gm=mysql_affected_rows();if($gm==1){$gotmatchrelocate=1;}
}else{
$sql="UPDATE my_members SET score=0 WHERE id='$id'";$result=mysql_query($sql);
}}
if($w==0){$sql="UPDATE my_members SET score=score-1 WHERE score>0";$result=mysql_query($sql);}}
if(($relocate>0 && $gotmatchrelocate<1) || ($relocate==0 && $nolocate==0)){restorem();echo '<script language="javascript">var answer = confirm ("No results were found. If you want to Search Your Results, click OK. If you want to Search All, click Cancel.");if (answer){window.location = "match_.php?searchtype='.$R.'";}else{window.location = "match_.php";} </script>';
}else{
echo "<BR><BR><BR><BR>";
$rr=mysql_query("SELECT id,score FROM my_members WHERE score>0 ORDER BY score DESC LIMIT 30");
while($row = mysql_fetch_array($rr)){
$id=$row['id'];
$score=$row['score'];
get_record($id,$score);}
echo '<span style="background-color:red"><b>You got '.mysql_num_rows($rr).' results.</b></span>';}
mysql_close();
//if($R<>"word" && !isset($S)){
echo '<center><div class="j"><center><h1>Search and Match Results</h1><br>
<a HREF="http://www.css-resources.com/">Home</a> <a HREF="profile-and-account-management.php">Account Management</a> <a HREF="match_.php?searchtype=all">Search All</a> <a HREF="match_.php?searchtype=first">Search These Results</a> <a HREF="#" onclick="saveresults()">Save These Results</a> <a HREF="match_.php?searchtype=word">Word Search</a></center></div></center>';//}
}}}}}}}
if($Entry==0 && isset($_SESSION['db']) && $R<>"word" && !isset($S)){ ?>
<center><div class='j'><center><h1>Search and Match</h1><form id='formpw' name="formpw" method="post" action="match_.php?searchtype=<?php echo $R; ?>" onsubmit="return validatepassword()"><br>
<a HREF="http://www.css-resources.com/">Home</a> <a HREF="profile-and-account-management.php">Account Management</a> <a HREF="register-with-captcha_.php">Register</a> <a HREF="login_.php">Login</a> <a HREF="match_.php?searchtype=word">Word Search</a></center></div></center>
<div id='myform'><center><h3>Search Criteria</h3><u><i><span style='color:maroon;font-weight:bold;font-size:18px'>Check or enter up to 10 search criteria.</span></i></u></center>
<center>
<table id='y' cellspacing=0 cellpadding=0 border=0>
<tr><th colspan='2' class='c'><b>Profile</b></th></tr>
<tr><td class='i'><label for="Group Name"><b>Group Name: </b></td><td><input type="text" name="groupname" size="20" maxlength="20" value=""></label></td></tr>
<tr><td class='i'><label for="City"><b>City: </b></td><td><input type="text" name="city" size="20" maxlength="33" value=""></label></td></tr>
<tr><td class='i'><label for="State"><b>State: </b></td><td>
<select name="state" size='4'>
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
<option value="AR">Arkansas</option>
<option value="CA">California</option>
<option value="CO">Colorado</option>
<option value="CT">Connecticut</option>
<option value="DE">Delaware</option>
<option value="DC">District of Columbia</option>
<option value="FL">Florida</option>
<option value="GA">Georgia</option>
<option value="HI">Hawaii</option>
<option value="ID">Idaho</option>
<option value="IL">Illinois</option>
<option value="IN">Indiana</option>
<option value="IA">Iowa</option>
<option value="KS">Kansas</option>
<option value="KY">Kentucky</option>
<option value="LA">Louisiana</option>
<option value="ME">Maine</option>
<option value="MD">Maryland</option>
<option value="MA">Massachusetts</option>
<option value="MI">Michigan</option>
<option value="MN">Minnesota</option>
<option value="MS">Mississippi</option>
<option value="MO">Missouri</option>
<option value="MT">Montana</option>
<option value="NE">Nebraska</option>
<option value="NV">Nevada</option>
<option value="NH">New Hampshire</option>
<option value="NJ">New Jersey</option>
<option value="NM">New Mexico</option>
<option value="NY">New York</option>
<option value="NC">North Carolina</option>
<option value="ND">North Dakota</option>
<option value="OH">Ohio</option>
<option value="OK">Oklahoma</option>
<option value="OR">Oregon</option>
<option value="PA">Pennsylvania</option>
<option value="RI">Rhode Island</option>
<option value="SC">South Carolina</option>
<option value="SD">South Dakota</option>
<option value="TN">Tennessee</option>
<option value="TX">Texas</option>
<option value="UT">Utah</option>
<option value="VT">Vermont</option>
<option value="VA">Virginia</option>
<option value="WA">Washington</option>
<option value="WV">West Virginia</option>
<option value="WI">Wisconsin</option>
<option value="WY">Wyoming</option>
</select>
</label></td></tr>
<tr><td class='i'><label for="Zip"><b>Zip: </b></td><td><input type="text" name="zip" size="5" maxlength="5" value=""></label></td></tr>
<tr><td colspan='2'>
<center><b>Proximity Search</b></center></td></tr>
<tr><td class='k'> </td><td align='left' style='color:blue'>*Selecting any of these will limit your results to the distance selected.</td></tr>
<tr><td class='k'><input type="checkbox" name="Willing_to_relocate" value="2" onchange="c()"></td><td>*Only find groups within 1000 miles of my group's zipcode</td></tr>
<tr><td class='k'><input type="checkbox" name="Willing_to_relocate" value="3" onchange="c()"></td><td>*Only find groups within 500 miles of my group's zipcode</td></tr>
<tr><td class='k'><input type="checkbox" name="Willing_to_relocate" value="4" onchange="c()"></td><td>*Only find groups within 200 miles of my group's zipcode</td></tr>
<tr><td class='k'><input type="checkbox" name="Willing_to_relocate" value="5" onchange="c()"></td><td>*Only find groups within 100 miles of my group's zipcode</td></tr>
<tr><td class='k'><input type="checkbox" name="Willing_to_relocate" value="6" onchange="c()"></td><td>*Only find groups within 50 miles of my group's zipcode</td></tr>
<tr><td class='k'><input type="checkbox" name="Willing_to_relocate" value="7" onchange="c()"></td><td>*Only find groups within 10 miles of my group's zipcode</td></tr>
<tr><td class='k'><input type="checkbox" name="Willing_to_relocate" value="8" onchange="c()"></td><td>*Only find groups within 2 miles of my group's zipcode</td></tr>
<tr><th colspan='2'><b> </b></th></tr>
<tr><th colspan='2' class='c'><b>Questions</b></th></tr>
<?php thecheckboxes(); ?>
<tr><th colspan='2'><b> </b></th></tr>
<input name="entry" type="hidden" value="1">
<input name='fieldname' type='hidden' value=''>
<input name='fieldvalue' type='hidden' value=''>
<tr><td class='k'> </td><td><BR><input type="submit" value="Submit" class='submit'>
<input type="reset" value="Reset" class='submit'></td></tr></table>
</form><BR><BR>
</div>
<?php
mysql_close();
}
?>
</body>
</html>